Skip to content

Instantly share code, notes, and snippets.

@zephyrmike
Last active September 27, 2019 22:22
Show Gist options
  • Save zephyrmike/0394d146234534fa343cc64361ce31d9 to your computer and use it in GitHub Desktop.
Save zephyrmike/0394d146234534fa343cc64361ce31d9 to your computer and use it in GitHub Desktop.
Useful HTACCESS Rules
/* http to https with www to non-www */
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
/* http to https with non-www to www */
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
/* prevent hotlinking */
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
RewriteRule \.(gif|jpg|png|svg)$ - [F]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment