将URL重写为index.php,但避免URL中包含index.php
我试图在内部将所有请求重定向到index.php,并使用 .htaccess 文件在外部重定向所有包含index.php 的请求。
因此像 http://host/test 这样的 URL 应该由 index.php 处理,而像 http://host/index.php/test 应重定向到 http://host/test 然后由index.php处理(不将浏览器重定向到index.php)
我尝试了以下操作,但总是收到一条消息“重定向太多.. ”:
RewriteRule ^index\.php/?(.*)$ /$1 [R,L]
RewriteRule .* index.php/$0 [L]
I'm trying to internally redirect all requests to index.php and externally redirect all requests that contain index.php using a .htaccess file.
So URLs like http://host/test should be processed by index.php and URLs like http://host/index.php/test should be redirected to http://host/test and then processed by index.php (without redirecting the browser to index.php)
I tried the following but always get a message "Too many redirects...":
RewriteRule ^index\.php/?(.*)$ /$1 [R,L]
RewriteRule .* index.php/$0 [L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要查看请求行中的 URL 以查看是否已请求
/index.php/...
:You need to look at the URL in the request line to see if
/index.php/…
has been requested:除此之外,如果您想在不重定向浏览器的情况下执行此操作,那么您不想使用
[R]
选项,这意味着R
重定向浏览器。试试这个:
Among other things, if you want to do it without redirecting the browser then you don't want to use the
[R]
option, which meansR
edirect the browser.Try this: