【发布时间】:2016-06-15 10:48:40
【问题描述】:
我有一个由多个域访问的服务器。 所有这些域都必须有 www。在前面。
只有一个域应该是 HTTPS,另一个是 HTTP,因为我只有一个域的 SSL 证书。
我在 .htaccess 文件中尝试了以下代码
重写引擎开启
# First force domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Then force https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^amanvida.eu [NC,OR]
RewriteCond %{HTTP_HOST} ^www.amanvida.eu [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]
应该强制 https 的域是 www.amanvida.eu
但是它没有按预期完全工作 https://www.amanvida.eu/nl/amanprana-serum-gezicht-shangri-la.html - 工作,当然
http://www.amanvida.eu/nl/amanprana-serum-gezicht-shangri-la.html - 有效
http://amanvida.eu/nl/amanprana-serum-gezicht-shangri-la.html - 有效
https://amanvida.eu/nl/amanprana-serum-gezicht-shangri-la.html - 重定向到主页
所以 4 种情况中有 3 种已经正常工作,但我想要用户已经在 https 站点上但不在 www 上的情况。域也可以正确重定向到页面,而不是主页。
我什至尝试像这样强制 www:
# First force domain to use www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
没有成功。
【问题讨论】: