Skip to content

Instantly share code, notes, and snippets.

@BernardoSilva
Created February 5, 2013 20:03
Show Gist options
  • Save BernardoSilva/4717188 to your computer and use it in GitHub Desktop.
Save BernardoSilva/4717188 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>
@saifnirob
Copy link

Not sure it's late to comment, but if you get me the code for .htaccess in how can I force to https and non-www site, that would be a big help here. FYI: the application running with Codeigniter 3.1.9 with Ubuntu 16.4 x64. Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment