0

我已经设法通过 .htaccess 使用以下规则在 https 中切换我的所有网站:

RewriteCond %{HTTPS} off [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]

现在我遇到了一个问题,因为一些 3rd 方服务使用 POST url,例如:

http://sub.mydomain.com/agreg/sms/service

被拒绝,因为它们被重定向并且现在 GET。

我想在每个带有^/agreg/方案的 url 上禁用这个“强制 https”的东西。我试过了

RewriteCond %{HTTPS} off [NC]
RewriteCond %{REQUEST_URI} !^/agreg
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]

但现在有重定向到http://sub.mydomain.com/app.php

我在这里错过了什么?

非常感谢你的帮助!

4

1 回答 1

2

问题:

我想用 ^/agreg/ 方案在每个 url 上禁用这个“强制 https”的东西。我试过了

RewriteCond %{HTTPS} off [NC]
RewriteCond %{REQUEST_URI} !^/agreg
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]

但现在有重定向到 http://sub.mydomain.com/app.php


嗯,根据规则,这是一个有效的结果。

有第二条规则将所有内容重定向到app.php. 这个:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]

例如,虽然传入的 URLhttp://sub.mydomain.com/agreg/sms/serviceSo被排除在第一条规则之外,但它在第二条规则中被重写。

解决方案:

假设预期的行为是从 BOTH 规则中排除包含字符串的任何 URL agreg,它应该是这样的:

RewriteCond %{HTTPS} off [NC]
RewriteCond %{REQUEST_URI} !/agreg        [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/agreg        [NC]
RewriteRule ^(.*)$ /app.php [QSA,L]

重写条件仅对下一条规则有效。有必要在最后一个规则块中添加相同的 NOT 条件。

于 2013-03-17T22:39:30.887 回答