mod重写单个网址.php

时间:2016-10-20 14:23:27

标签: php .htaccess mod-rewrite

如何使用以下代码重写单个网址?

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

1 个答案:

答案 0 :(得分:1)

您可以更改正则表达式模式,使其仅定位home.php

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+(home)\.php[?/\s] [NC]
RewriteRule ^ %1 [R=301,L]

RewriteRule ^(home)/?$ $1.php [L]