【问题标题】:rewrite https and www重写 https 和 www
【发布时间】:2016-10-05 10:34:34
【问题描述】:

现在我有一个网站 https。

http://www.example.com -> https://www.example.com = 好的!

但是,我对 www 有疑问 ://example.com -> s://example.com = 不好

我想在下面有这个重定向: ://example.com -> s://www.example.com

如何使用 RewriteCond 和 RewriteRule ?请帮帮我!

谢谢!

【问题讨论】:

  • 我不知道你在问什么。如果有,请显示代码。如果可以,请使用语言,如果正在使用特定的库。
  • RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{SERVER_NAME} =example.com [NC,OR] RewriteCond %{SERVER_NAME} =www.example.com [NC] RewriteRule ^(.*) $example.com [R=301,L]
  • 好的,很抱歉在这里无法提供帮助,不熟悉 apache 重写规则。对不起。

标签: .htaccess mod-rewrite


【解决方案1】:

对所有请求强制执行 https 并重定向到 www.example.com

# force https and www
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R,L]

# if already https without www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R,L]

【讨论】:

  • 非常感谢您的帮助!
猜你喜欢
  • 2014-12-16
  • 2017-12-04
  • 2015-01-10
  • 1970-01-01
  • 1970-01-01
  • 2018-02-02
  • 1970-01-01
  • 1970-01-01
  • 2020-11-28
相关资源
最近更新 更多