Skip to content

Instantly share code, notes, and snippets.

@jlabs
Created August 12, 2020 09:28
Show Gist options
  • Save jlabs/e80e786e85bf1928cd58086a7ad8c3d4 to your computer and use it in GitHub Desktop.
Save jlabs/e80e786e85bf1928cd58086a7ad8c3d4 to your computer and use it in GitHub Desktop.
# ----------------------------------------------------------------------
# | Cleaning URLs |
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
# Remove www from URL's
RewriteCond %{HTTP_HOST} ^www\.(.+)
# RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
# Make all traffic go over https
# RewriteCond %{HTTP:X-Forwarded-Proto} !https
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Remove trailing slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment