简体   繁体   English

规则的mod_rewrite和.htaccess异常

[英]mod_rewrite and .htaccess exception to the rule

I want to hide the .php extension throughout my site, I have this snippet and it works fine. 我想在整个网站中隐藏.php扩展名,我有此摘要,并且工作正常。 However I have one URL that I want to be an exception to the rule, that is I want it have the .php intact and all it's $_GET params. 但是我有一个URL,我希望成为该规则的例外,也就是说,我希望它具有完整的.php及其全部$ _GET参数。

How can I include that exception into this snippet? 如何将该异常包含在此代码段中? And why does it work? 为何起作用?

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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

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

You can add exception like this: 您可以添加如下异常:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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

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

btw this code and comment look like something I would have written it in the past :) 顺便说一下,这段代码和注释看起来就像我过去写过的东西:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM