我想知道如何在重写规则上从重定向中排除特定的.php文件。
site.com/images/resizer.php
不断重定向到site.com/images/resizer/
,这是一个问题,因为我有一些标题设置如下:site.com/images/resizer/?page=2
在我的 .htaccess 中,我有两个重写规则,可以删除.php文件扩展名并在 url 末尾强制斜杠,我想排除该调整器.php被重写。
#if page with .php is requested then remove the extension
RewriteCond %{THE_REQUEST} s/+(.+?).php[s?] [NC]
RewriteRule ^ /%1/ [R=302,L,NE]
#Force a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} s/+([^.]+?[^/.])[s?] [NC]
RewriteRule ^ /%1/ [R=302,L]
#silently rewrite to webroot
RewriteCond %{REQUEST_URI} !/webroot/ [NC]
RewriteRule ^ /webroot%{REQUEST_URI} [L]
#.php ext hiding
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
我希望调整大小如下:site.com/images/resizer.php?page=2
我尝试在斜杠和隐藏扩展规则下添加以下内容.php但它不起作用,我完全被困住了。.
失败的尝试(在两个重写规则下)
RewriteCond %{REQUEST_URI} !^/images/resizer$ [NC]
和
RewriteRule ^images/resizer/?$ /images/resizer.php [NC,L]
你很接近。在这两个重定向规则中,添加一个条件:
RewriteCond %{REQUEST_URI} !^/images/resizer.php
所以:
#if page with .php is requested then remove the extension
RewriteCond %{REQUEST_URI} !^/images/resizer.php
RewriteCond %{THE_REQUEST} s/+(.+?).php[s?] [NC]
RewriteRule ^ /%1/ [R=302,L,NE]
#Force a trailing slash to be added
RewriteCond %{REQUEST_URI} !^/images/resizer.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} s/+([^.]+?[^/.])[s?] [NC]
RewriteRule ^ /%1/ [R=302,L]