Skip to content

Instantly share code, notes, and snippets.

@xyznaveen
Last active June 22, 2018 14:52
Show Gist options
  • Save xyznaveen/d9b16707aca7cccd7c7aff9bfab7aca1 to your computer and use it in GitHub Desktop.
Save xyznaveen/d9b16707aca7cccd7c7aff9bfab7aca1 to your computer and use it in GitHub Desktop.
.htaccess file to force www, htttps and redirect all requests to index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Redirect all requests to index.php only if it is not a directory or file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php/$1 [L]
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment