views:

44

answers:

1

I'd like to have all requests to http://example.com/controller redirected to http://example.com/index.php/controller without changing the url, and this is what my .htaccess file looks like:

# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]

  RewriteBase /
  RewriteCond %{HTTP_HOST} ^www.example.com [NC]
  RewriteRule ^(.*)$ http://example.com/$1 [R=301] 
</IfModule>

Unfortunately, this doesn't work. All requests to http://example.com/controller get routed to the home controller, and the url doesn't change. And all requests to http://www.example.com/controller get routed to http://example.com/index.php/controller and the url DOES change in the address bar.

Any idea what I'm missing or doing wrong?

+1  A: 

Put those rules that cause an external redirect in front of those that cause an internal redirect. So:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} =www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Gumbo
Thanks for the quick response! I tried that, and I still have the same problem. All queries like http://myurl.com/controller or http://www.myurl.com/controller (with the www) lead to the default home page. Any idea why?
itwasthewind
Doesn't sound like an .htaccess problem. I think you need to mess with your config/routes.php file.
Keyo
In codeigniter, my routes.php file has only two lines: $route['default_controller'] = "Home";$route['scaffolding_trigger'] = "";What else should I add?
itwasthewind