.htaccess htaccess重定向到HTTPS
我一直在想办法只将一个域重定向到HTTPS,但还没有找到一个好的解决方案。我可以使用https将所有请求重定向到https=条件是,但我托管多个域,只有一个域具有SSL 这给了我一些成功.htaccess htaccess重定向到HTTPS,.htaccess,mod-rewrite,redirect,.htaccess,Mod Rewrite,Redirect,我一直在想办法只将一个域重定向到HTTPS,但还没有找到一个好的解决方案。我可以使用https将所有请求重定向到https=条件是,但我托管多个域,只有一个域具有SSL 这给了我一些成功 RewriteCond %{HTTP_HOST} ^(127\.0\.0\.1|localhost)$ RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 但它似乎没有重定向像www.my
RewriteCond %{HTTP_HOST} ^(127\.0\.0\.1|localhost)$
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
但它似乎没有重定向像www.mydomain.com/order/和mydomain.com/order这样的URL/
基本上,它只适用于当前位于www.mydomain.com或mydomain.com的主页
我遗漏了什么?您的问题是:
RewriteCond %{HTTP_HOST} ^(127\.0\.0\.1|localhost)$
也就是说,“如果主机是127.0.0.1
或localhost
,则只使用下一个RewriteRule
。”如果您在同一台服务器上托管mydomain.com
,则它将不匹配。您需要添加要重定向的域的名称。例如:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
那真是一种享受。不过最后我走了一条稍微不同的路线。我最终使用了RewriteCond%{SERVER_NAME}^(www\.domain\.com | domain\.com)RewriteCond%{HTTPS}!在重写规则时(.*)https://%{HTTP_HOST}%{REQUEST_URI}[R=301,L]