Skip to content

Instantly share code, notes, and snippets.

@richjenks
Last active April 16, 2016 07:17
Show Gist options
  • Save richjenks/7c5e52c6b211139ae6ba to your computer and use it in GitHub Desktop.
Save richjenks/7c5e52c6b211139ae6ba to your computer and use it in GitHub Desktop.
Clean URLs
<IfModule mod_rewrite.c>
# Force https
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Remove www.
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Enforce trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment