簡體   English   中英

如何從.htaccess重定向(rewriteRule)中排除.php文件?

[英]How to exclude .php file from .htaccess redirect(rewriteRule)?

我想知道如何排除特定的.php文件重定向重寫規則。

site.com/images/resizer.php保持重定向到site.com/images/resizer/ ,這是一個問題,因為我有一些標題設置如下: site.com/images/resizer/?page=2

在我的.htaccess中,我有兩個重寫規則,刪除.php文件擴展名並在網址末尾強制斜杠,我想排除resizer.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]

我希望resizer如下: site.com/images/resizer.php?page=2

我嘗試在斜杠和.php隱藏擴展規則下添加以下內容,但它不起作用,我完全堅持這個..

失敗的嘗試(在rewriteRule下)

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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM