Remove index.php and add www in htaccess Codeigniter Remove index.php and add www in htaccess Codeigniter codeigniter codeigniter

Remove index.php and add www in htaccess Codeigniter


To get Codeigniter running on apache you need a simple .htaccess and config.php setup.

.htaccess

RewriteEngine On# Redirect non-www to wwwRewriteCond %{HTTP_HOST} !^www\.RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]# Remove WWW from the url#RewriteCond %{HTTPS} !=on#RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]# Optional to redirect trailing slashes#RewriteRule ^(.*)/$ /$1 [L,R=301]# Point all URI to codeigniter bootstrap except direct access to file or dirRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.php [L]

application/config/config.php

$config['base_url']  = '';$config['index_page'] = '';$config['uri_protocol'] = 'AUTO';

This will produce:

www.site.com/reviews/acticle/3 --> site.com/reviews/acticle/3www.site.com/index.php/reviews/acticle/3 --> site.com/reviews/acticle/3

and also get rid of ?.


To remove index.php from codeigniter:

RewriteEngine onRewriteBase /RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php?/$1 [L]