Skip to content

Instantly share code, notes, and snippets.

@smtir
Forked from BernardoSilva/.htaccess
Created July 16, 2016 11:33
Show Gist options
  • Select an option

  • Save smtir/dd5ee3dcacf021644b9b3b0d5950624b to your computer and use it in GitHub Desktop.

Select an option

Save smtir/dd5ee3dcacf021644b9b3b0d5950624b to your computer and use it in GitHub Desktop.
.htaccess for Codeigniter to avoid index.php and force www. before any URL
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
# BEGIN force www before URL
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# END for www on URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment