簡體   English   中英

Mod Rewrite 停止規則?

[英]Mod Rewrite stop at rule?

I have the following mod rewrite in my .htaccess and when I go to /commPortal.php it still ends up routing me to index2.php.

RewriteRule ^commportal/(.+)$ commPortal.php?data=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index2.php [QSA,L]

RewriteCond %{REQUEST_URI} \.php [NC]
RewriteRule ^ index2.php [QSA,L]

這似乎是由於RewriteRule ^commportal/(.+)$ commPortal.php?data=$1 [L]然后被:

RewriteCond %{REQUEST_URI} \.php [NC]
RewriteRule ^ index2.php [QSA,L]

有沒有辦法讓RewriteCond %{REQUEST_URI} \.php [NC]看到 commPortal.php 而不是 /commportal 如果已經有匹配的重寫規則,甚至忽略它?

將您的最后一條規則更改為:

RewriteRule ^commportal/(.+)$ commPortal.php?data=$1 [L,QSA,NC]

RewriteRule ^index2\.php$ - [L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index2.php [L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule \.php$ index2.php [L,NC]

RewriteCond %{ENV:REDIRECT_STATUS} ^$條件只有在此規則之前沒有內部重寫時才會為真,因此執行此規則之前只有沒有其他規則被觸發。

使用包含原始請求而不是重寫請求的THE_REQUEST變量的另一種選擇:

RewriteCond %{THE_REQUEST} !\s/+commportal/ [NC]
RewriteRule \.php$ index2.php [L,NC]

您能否僅根據您顯示的示例嘗試以下操作。 請確保在測試您的 URL 之前清除您的瀏覽器緩存。

RewriteRule ^commportal/(.+)$ commPortal.php?data=$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index2.php [QSA,L]

RewriteCond %{REQUEST_URI} !commportal\.php/?$ [NC]
RewriteCond %{REQUEST_URI} \.php [NC]
RewriteRule ^ index2.php [QSA,L]

暫無
暫無

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

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