I’m working on a CodeIgniter based application. My htacess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /
RewriteRule ^(.*)$ /index.php?$1 [L]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
This works great for the most part, and I can access controllers and methods like this:
http://example.com/controller/method/args
However, if it is appended with a www, like this
http://www.example.com/foo
It redirects to
http://example.com/index.php?foo
The page displayed is always the index page of my site.
I added the last pair of RewriteCond / RewriteRule simply to remove www if present.
I’m not quite sure how to get it to work the way I want, so that
http://www.example.com/foo
just redirects to
http://example.com/foo
EDIT
From my CI config file:
$config['base_url'] = 'http://example.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
As mentioned in the comment.
Your rewrite rule
RewriteRule ^(.*)$ /index.php?$1 [L]should be placed at the bottom. Order matters in this case due to your[L]flag.