开发者

URL Rewriting to have all requests to http://example.com/controller redirected to http://example.com/index.php/controller without changing the url

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.


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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜