Skip to content

Instantly share code, notes, and snippets.

@willyarisky
Created May 1, 2019 02:32
Show Gist options
  • Save willyarisky/4d19f8dde599236ea62e2c678a6b2347 to your computer and use it in GitHub Desktop.
Save willyarisky/4d19f8dde599236ea62e2c678a6b2347 to your computer and use it in GitHub Desktop.
Redirect to www and https
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Force SSL
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]
# Disable www
RewriteCond %{HTTP_HOST} =www.domain.com
RewriteRule (.*) https://domain.com/$1 [R=301,L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment