【发布时间】:2015-01-13 02:15:42
【问题描述】:
大家好,有人可以帮助我使用 .htaccess 规则来删除网址末尾的 /index.php
如果有人尝试访问的示例:
the-url-address.html/index.php
另一个网址地址.html/index.php
他们应该被重定向到:
-url-address.html
另一个网址地址.html
从 url 末尾删除 /index.php
【问题讨论】:
大家好,有人可以帮助我使用 .htaccess 规则来删除网址末尾的 /index.php
如果有人尝试访问的示例:
the-url-address.html/index.php
另一个网址地址.html/index.php
他们应该被重定向到:
-url-address.html
另一个网址地址.html
从 url 末尾删除 /index.php
【问题讨论】:
您可以在 DOCUMENT_ROOT/.htaccess 文件中使用此规则:
# set index.php as the default handler
DirectoryIndex index.php
RewriteEngine On
# remove index.php from the end of URI
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
【讨论】:
http://site.com/dir/index.php重定向到http://site.com/dir
http://site.com/index.php,它将被重定向到http://site.com/,但如果您输入:http://site.com/somedir/index.php,那么它将被重定向到:http://site.com/somedir
这在我的问题中已解决,您需要添加
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
就在 RewriteEngine On call 的下方
示例:
########## Begin - RewriteEngine enabled
RewriteEngine On
########## End - RewriteEngine enabled
########## remove index.php from the end of URI
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
##########
【讨论】: