.htaccess使用条件页面重定向到https

时间:2019-05-31 19:45:07

标签: regex .htaccess mod-rewrite url-rewriting

我有以下.htaccess

RewriteEngine On

RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !(/webservice|/api)
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !\.(gif|jpg|png|css|js|swf)$ index.php [L]

我希望所有页面都重定向到https,除了/ webservice和/ api之外,我希望它们同时使用http和https打开。

在https请求中,一切正常,问题是当我尝试访问http时。

问题

http://www.local.test/sub/pt-br/webservice redirect to https://www.local.test/index.php

http://www.local.test/sub/pt-br/api redirect to https://www.local.test/index.php

有什么想法可以使它起作用吗?

1 个答案:

答案 0 :(得分:0)

更改

RewriteCond %{REQUEST_URI} !(/webservice|/api)

RewriteCond %{REQUEST_URI} !^(\/webservice|\/api|\/sub\/pt-br\/webservice|\/sub\/pt-br\/api)

RewriteCond %{REQUEST_URI} !^\/webservice
RewriteCond %{REQUEST_URI} !^\/sub\/pt-br\/webservice
RewriteCond %{REQUEST_URI} !^\/api
RewriteCond %{REQUEST_URI} !^\/sub\/pt-br\/api