.htaccess仅在几个文件上重写并删除.php

时间:2014-03-24 20:30:36

标签: php regex apache .htaccess mod-rewrite

我正在尝试将所有.php文件扩展名重写为/

我得到了这个代码:

RewriteEngine On

# hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

然而,它打破了我正在与数据库交谈的管理页面,例如具有代码并使用URL中断的页面:

创建-ticket.php?设备= XBOX + 360

我需要将扩展​​名留在几页......

有没有办法可以使用上面的代码,但只能用于特定文件,而不是每个以.php结尾的文件?

谢谢, -O

1 个答案:

答案 0 :(得分:0)

您可以这样排除:

RewriteEngine On

# hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} !/(create-ticket|admin)\.php [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]