Skip to content

Instantly share code, notes, and snippets.

@celsowhite
Last active August 17, 2018 14:02
Show Gist options
  • Save celsowhite/5ee2e102b1f2cf0025ab4693d3dff60c to your computer and use it in GitHub Desktop.
Save celsowhite/5ee2e102b1f2cf0025ab4693d3dff60c to your computer and use it in GitHub Desktop.
Common rewrites I use in projects.
# Force all www to redirect to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
# Force all http to redirect to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Single page app rewrite on Apache servers. Ensures routing system works properly.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment