我知道这是一个常见的话题,但我已尽最大努力借助在网上搜索到的解决方案来解决它。
我们有一个链接到子域 secure.mysite.com 的证书,我们希望实现以下目标:
我们需要在以下路径及其子页面上强制使用 SSL:
http://mysite.com/services[/.../...] => https://secure.mysite.com/services[/.../...]
http://mysite.com/login[/.../...] => https://secure.mysite.com/login[/.../...]
http://mysite.com/member[/.../...] => https://secure.mysite.com/member[/.../...]
http://mysite.com/admin[/.../...] =>https://secure.mysite.com/admin https://secure.mysite.com/admin
我们要在所有非安全路径上添加 www(除上述路径外的所有路径)
我们想要删除所有安全路径上的 www(上面提到的所有路径)
以下是我放入 .htaccess 文件中的内容,但没有成功:
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(services|login|member|admin)$ https://secure.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(services|login|member|admin)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# remove www from host when HTTPS
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{HTTPS} =on
RewriteRule ^ http%2://%1%{REQUEST_URI} [L,R=301]
# add www from host when HTTP
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Zend redirect logic
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
经过一些更正:
RewriteEngine On
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(services|login|member|admin) https://secure.mysite.com%{REQUEST_URI} [L,R=301]
# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(services|login|member|admin) http://mysite.com%{REQUEST_URI} [L,R=301]
# remove www from host when HTTPS
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
# add www from host when HTTP
RewriteCond %{HTTPS} =off
RewriteCond %{HTTP_HOST} !^(www|secure)\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)