htaccess的力量WWW到非www考虑的HTTP或HTTPS [英] htaccess force www to non-www with consideration of http or https

查看:196
本文介绍了htaccess的力量WWW到非www考虑的HTTP或HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的停留在转换这个美丽的htaccess的脚本(规则),这迫使非www到www网址考虑HTTP或HTTPS其完美的工作,但我不能让它相反的方式工作,从WWW到非www可以请你帮我?

I am really stuck at conversion of this beautiful htaccess script (rule) which force non-www to www url considering the http or https its perfectly working but I cant make it work opposite way from www to non-www can you please help me?

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

感谢你,我真的很停留在那些htaccess的符号!

Thank you I am really stuck at those htaccess symbols!

推荐答案

有关制定 WWW到非www 上面code将无法正常工作捕捉的RewriteCond作品。你需要将它们分解成2的规则是这样的:

For making www to non-www above code will not work because of the way variable capturing works in RewriteCond. You need to break them into 2 rules like this:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

这篇关于htaccess的力量WWW到非www考虑的HTTP或HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆