将 URL 重写为 index.php 但避免在 URL 中使用 index.php
我正在尝试将所有请求在内部重定向到 index.php,并使用 .htaccess 文件从外部重定向所有包含 index.php 的请求.
I'm trying to internally redirect all requests to index.php and externally redirect all requests that contain index.php using a .htaccess file.
所以像 http://host/test 这样的 URL 应该由 index.php 和像 http://host/index.php/test 应该重定向到 http://host/test 然后由 index.php 处理(无需将浏览器重定向到 index.php)
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]
需要查看请求行中的 URL 来查看是否已经请求了 /index.php/...
:>
You need to look at the URL in the request line to see if /index.php/…
has been requested:
RewriteCond %{THE_REQUEST} ^GET\ /index\.php/?([^ ]*)
RewriteRule ^index\.php/?(.*) /$1 [R,L]
RewriteCond $0 !^index\.php($|/)
RewriteRule .* index.php/$0 [L]