重写规则使目录url结构加载php页面?

问题描述 投票:1回答:1

我有以下重写规则:

RewriteEngine On
RewriteRule    ^test    test.php    [NC,L]  

这允许我通过以下方式访问页面:

http://www.example.com/testhttp://www.example.com/test.php但我如何防止http://www.example.com/test.php被访问?

谢谢

.htaccess url-rewriting
1个回答
0
投票

如果要在直接访问forbidden error uri时显示403 /test.php页面,可以使用以下规则:

RewriteCond %{THE_REQUEST} /test\.php [NC]
RewriteRule ^test\.php$ - [R=403,L]

如果要将/test.php重定向到新的uri /test,请使用以下命令:

RewriteCond %{THE_REQUEST} /test\.php [NC]
RewriteRule ^test\.php$ /test [L,R]
© www.soinside.com 2019 - 2024. All rights reserved.