[英]Redirect certain pages from http to https; redirect rest of site to www
我的要求如下:
我已经尝试了Stack Overflow此处列出的许多解决方案,但是似乎都没有用。
这是我的htaccess文件的相关部分:
#force https for certain pages
RewriteCond %{HTTPS} !=on
RewriteRule ^(login2\-test\.php.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
#redirect all pages to www
RewriteCond %{HTTPS} !=off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
将所有页面重定向到www都可以。 但是,login2-test?Switch = ftr(位于reg /子目录中)到https的重定向结果不匹配,因此该页面使用http显示。
我已经将该行重写如下:
RewriteRule ^(reg\/)(login2\-test\.php.*)$ https:www.domain.com/$1$2 [L,R]
这至少匹配/重定向到https,但是浏览器无法解析它。
我已经交换了规则的顺序(例如,www首先重定向); 那没有帮助。
我将不胜感激-我已经为此努力了一段时间。
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.