htaccess 重定向到 www,不包括 https 和 http 子域
这就是我目前所拥有的,我正在尝试将 http://something.com 重定向到 http://www.something.com 但如果它是一个子域,则不会执行此类操作,因此 http://other.somethings.com 将保持不变并且基于 https/http
目前有..
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
So this is what I currently have, I'm trying to redirect http://something.com to http://www.something.com but if its a subdomain do no such things, so http://other.somethings.com will stay the same AND conditional based on https/http
Currently have..
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试此规则:
这只会将请求重定向到主机 example.com 并保留 HTTPS(如果使用)。
Try this rule:
This will only redirect requests to the host example.com and keep HTTPS if it’s used.
虽然有点乏味,但并不是那么困难。还有另一个名为 HTTPS 的重写条件变量,即使您没有运行 mod_ssl,也可以安全使用。然后,您将链接两个 RewriteCond 检查,并得到如下所示的结果:
缺点是您现在将有问题的域硬编码到 .htaccess 中。我不知道有什么方法可以在不对域进行硬编码的情况下使其工作。
It's not that difficult, although it is a bit tedious. There's another rewrite conditional variable called HTTPS which is safe to use even when you don't have mod_ssl running. You'd then chain two RewriteCond checks, and get something like this:
The downside is that you are now hardcoding the domain in question into the .htaccess. I'm not aware of a way to make it work without hardcoding the domain.