【发布时间】:2019-07-08 11:05:13
【问题描述】:
- .html 应该从每个 URL 的末尾删除
- 所有 http 链接都应该转到 https
- 所有 www 链接都应该转到非 www
我如何使用 .htaccess 来实现这一点,这是否足以让 Google 正确抓取我的网站而不产生重复的链接?
【问题讨论】:
标签: .htaccess http url redirect https
我如何使用 .htaccess 来实现这一点,这是否足以让 Google 正确抓取我的网站而不产生重复的链接?
【问题讨论】:
标签: .htaccess http url redirect https
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。
【讨论】: