htaccess使用RewriteRule和RewriteCond重定向特定的url

时间:2017-03-21 12:35:11

标签: .htaccess mod-rewrite

我必须从

重定向(301)

http://domain/index.phphttp://domain/

我是按照以下规则完成的:

RewriteCond%{THE_REQUEST} ^。* / index.php

RewriteRule ^(。*)index.php $ / $ 1 [R = 301,L]

确定。它工作,但我不想允许从网址重定向:

http://domain/ ASD 的index.php

我试图改变条件,如:

RewriteCond%{THE_REQUEST} ^ / index.php

RewriteCond%{THE_REQUEST} ^ / index.php

但没有成功。

那么,如何仅从http://domain/index.php重定向到http://domain/

ps:我不想使用REDIRECT命令

2 个答案:

答案 0 :(得分:1)

试试这个:

RewriteRule ^index.php$ / [R=301,L]

答案 1 :(得分:0)

您可以使用以下规则:

RewriteEngine on

RewriteCond %{THE_REQUEST} \s/index\.php\s [NC]
RewriteRule ^ / [L,R]
相关问题