【问题标题】:Redirect all http to https, all www to non-www, and remove .html from all urls将所有 http 重定向到 https,将所有 www 重定向到非 www,并从所有 url 中删除 .html
【发布时间】:2019-07-08 11:05:13
【问题描述】:
  • .html 应该从每个 URL 的末尾删除
  • 所有 http 链接都应该转到 https
  • 所有 www 链接都应该转到非 www

我如何使用 .htaccess 来实现这一点,这是否足以让 Google 正确抓取我的网站而不产生重复的链接?

【问题讨论】:

    标签: .htaccess http url redirect https


    【解决方案1】:
    RewriteEngine on
    
    # remove .html from all files
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.*)$ $1.html
    
    # redirect all http to https and all www to non-www
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
    

    这似乎已经完成了工作。我在网上找到的几个答案都失败了 - http://www.example.com 经常被错误地定向到 https://www.example.com

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-12
      • 1970-01-01
      • 2019-03-08
      • 2016-10-28
      • 2017-01-14
      • 2020-05-16
      • 1970-01-01
      相关资源
      最近更新 更多