Mod 重写停止于规则?
Mod Rewrite stop at rule?
我在我的 .htaccess 中重写了以下 mod,当我转到 /commPortal.php 时,它仍然最终将我路由到 index2.php。
RewriteRule ^commportal/(.+)$ commPortal.php?data= [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= [L]
然后被以下人接走:
RewriteCond %{REQUEST_URI} \.php [NC]
RewriteRule ^ index2.php [QSA,L]
有什么方法可以让 RewriteCond %{REQUEST_URI} \.php [NC]
看到 commPortal.php 而不是 /commportal 或者如果已经有匹配的重写规则甚至忽略它?
将您的最后一条规则更改为:
RewriteRule ^commportal/(.+)$ commPortal.php?data= [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= [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]
我在我的 .htaccess 中重写了以下 mod,当我转到 /commPortal.php 时,它仍然最终将我路由到 index2.php。
RewriteRule ^commportal/(.+)$ commPortal.php?data= [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= [L]
然后被以下人接走:
RewriteCond %{REQUEST_URI} \.php [NC]
RewriteRule ^ index2.php [QSA,L]
有什么方法可以让 RewriteCond %{REQUEST_URI} \.php [NC]
看到 commPortal.php 而不是 /commportal 或者如果已经有匹配的重写规则甚至忽略它?
将您的最后一条规则更改为:
RewriteRule ^commportal/(.+)$ commPortal.php?data= [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= [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]