Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess重定向到HTTPS_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

.htaccess htaccess重定向到HTTPS

.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

我一直在想办法只将一个域重定向到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.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]