.htaccess规则删除url末尾的index.php

时间:2013-11-07 09:47:33

标签: .htaccess redirect

大家好,有人可以用.htaccess规则帮我删除网址末尾的/index.php

例如,如果有人试图访问:

-URL-address.html / index.php的

另一个-URL-address.html / index.php的

他们应该被重定向到:

-URL-address.html

另一个-URL-address.html

从url的末尾删除/index.php

2 个答案:

答案 0 :(得分:2)

您可以在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]

答案 1 :(得分:0)

这在我的问题中解决了,你需要添加

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

正好在RewriteEngine On the 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]
##########