【问题标题】:I want to remove the www from url on https using .htaccess我想使用 .htaccess 从 https 上的 url 中删除 www
【发布时间】:2012-03-19 15:12:42
【问题描述】:

我想通过 .htaccess 从 https url 中删除 www。 例如

我想改变

https://www.example.com/ 到https://example.com/

我尝试了很多规则

RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST}  ^www\.example\.com$ [NC]  
RewriteRule ^(.*)$    https://example.come/$1 [L]

RewriteCond %{SERVER_PORT} ^443
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) https://example.com$1 [L,R,QSA]

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

但没有任何效果。请帮帮我

【问题讨论】:

    标签: .htaccess url-rewriting


    【解决方案1】:

    请确定您是否使用 X-Forwarding,然后试试这个:

    RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^(.*)$ https://example.com/$1 [R,L]
    

    【讨论】:

      【解决方案2】:

      试试:

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

      【讨论】:

      • 这会尊重输入的任何方案吗?例如。 http://www.example.com -> http://example.comhttps://www.example.com -> https://example.com
      猜你喜欢
      • 2015-09-09
      • 2016-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 2013-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多