HTAccess 重写规则仅重定向第一条规则

问题描述 投票:0回答:1

这个 RewriteRule 工作正常:

RewriteRule ^sellers/?$ /sellers/index.php [NC,L]

但这其他人没有

RewriteRule ^sellers/login/?$ /sellers/login.php [NC,L]

RewriteRule ^sellers/logout/?$ /sellers/logout.php [NC,L]

RewriteRule ^sellers/profile/?$ /sellers/profile.php?p=profile-content [NC,L]

完整的 .htaccess 看起来像:

RewriteEngine On  
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^sellers/?$ /sellers/index.php [NC,L] 
RewriteRule ^sellers/login/?$ /sellers/login.php [NC,L] 
RewriteRule ^sellers/logout/?$ /sellers/logout.php [NC,L] 
RewriteRule ^sellers/profile/?$ /sellers/profile.php?p=profile-content [NC,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^www.camelando.aaa$ [NC,OR]
RewriteCond %{HTTP_HOST} ^camelando.aaa$
RewriteRule ^(.*)$ https://camelando.aaa/$1 [R=301,L]

重定向安全网址以更正本地服务器(.aaa 域)中的 php 文件

php security url
1个回答
0
投票

您在 .htaccess 重写规则中遇到的问题似乎是由于规则的顺序和结构造成的。第一条规则是捕获所有以卖家开头的请求,并在其他规则有机会应用之前重定向它们。要解决此问题,您需要对规则重新排序,以便首先评估更具体的规则。以下是调整它们的方法:

将更具体的重写规则放在更通用的规则之前。 确保每个规则中的模式足够具体,仅匹配预期的请求。

以下是规则的修订顺序:

RewriteRule ^sellers/login/?$ /sellers/login.php [NC,L]
RewriteRule ^sellers/logout/?$ /sellers/logout.php [NC,L]
RewriteRule ^sellers/profile/?$ /sellers/profile.php?p=profile-content [NC,L]
RewriteRule ^sellers/?$ /sellers/index.php [NC,L]

通过这些更改,您的 .htaccess 文件现在应该可以正确解释卖家/登录、卖家/注销和卖家/个人资料,然后再返回到更通用的卖家规则。每个请求都会按顺序进行评估,因此按照从最具体到最一般的顺序构建重写规则非常重要。这样,预期的规则将在应用任何后续的更通用的规则之前捕获请求。

© www.soinside.com 2019 - 2024. All rights reserved.