URL 重写,将所有对 http://example.com/controller 的请求重定向到 http://example.com/index.php/controller 而不更改 url
我希望将 http://example.com/controller 的所有请求重定向到 http://example.com/index.php/controller 而不更改 url,这就是我的 . htaccess 文件看起来像:
# 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>
不幸的是,这不起作用。所有对 http://example.com/controller 的请求都会路由到家庭控制器,而 URL 不会改变。 所有对 http://www.example.com/controller 的请求都会路由到 http://example.com/index.php/controller 并且地址栏中的网址确实发生了变化。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将导致外部重定向的规则放在导致内部重定向的规则之前。所以:
Put those rules that cause an external redirect in front of those that cause an internal redirect. So: