【问题标题】:Issue with htaccess after migration to https (website + KeyCDN)迁移到 https 后出现 htaccess 问题(网站 + KeyCDN)
【发布时间】:2017-08-06 14:17:33
【问题描述】:

尽管在论坛上进行了数小时的测试和阅读,但我仍有一个无法解决的问题。

昨天我按照以下步骤从 http 迁移到 https:

  1. 在我的托管面板中激活 SSL 证书(我的网站的共享 Apache 托管中包含的 Let's Encrypt 证书)
  2. 将所有硬编码链接更新为 HTTPS(规范 url、js 等 + 每个硬编码 KeyCDN 链接)
    • 使用this tool 检查的每个页面:“未发现问题”
  3. 在我的 KeyCDN 面板中启用共享 SSL + 强制 SSL:“启用”+ 更新源 URL(http 到 https)
  4. 清除 KeyCDN 缓存

在这一步,我必须在我的 htacess 中编写到 https 的 301 重定向,以完成该过程。

但是:已经在我的 htaccess 中编码的 301 重定向不再起作用了。 从昨天开始,我不得不停用我的 htaccess 文件,这对我的 SEO 来说是个大问题。

错误消息:“重定向过多”

这是我的 htaccess :

<files .htaccess>
order allow,deny
deny from all
</files>

Options -Indexes
ErrorDocument 403 http://www.example.com
ErrorDocument 404 /404.html

##  CANONICAL DOMAIN WITH 301 REWRITE WITHOUT WWW TO WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [QSA,L,R=301]

##  301 REWRITE WITHOUT .HTML AT THE END OF FILES
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

##  OLD SITE WITH 301 REWRITE WITHOUT INDEX.HTML/.PHP IN URLS
RewriteEngine On
Redirect 301 /index.php  http://www.example.com
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html?$ http://www.example.com/$1 [R=301,L]

##  301 REWRITE FOR MOVED PAGES
Redirect 301 /old-url-1 http://www.example.com/new-url-1

我尝试了很多代码来进行从http到https的301重定向,例如:

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

没有任何效果:即使使用以前的 htaccess,网站也不再显示(“重定向太多”),我不得不停用。

你能帮我写一个好的 301 重定向吗:

  • 从 http 到 https,
  • 没有 www 到 www,
  • 不带 .html 文件扩展名
  • 在我的目录末尾没有斜杠 (/)

我的网站仅使用 html/css(无 CMS)构建。

提前谢谢你,因为我认为其他地方存在重定向冲突。

【问题讨论】:

    标签: apache .htaccess ssl https http-status-code-301


    【解决方案1】:

    这是答案:

    <files .htaccess>
    order allow,deny
    deny from all
    </files>
    
    Options +FollowSymlinks
    Options -MultiViews
    RewriteEngine on
    
    RewriteRule ^/normal/secure(/.*) https://%{HTTP_HOST}$1 [R=301,L]
    RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
    RewriteRule ^ /%1 [NC,L,R]
    
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^ %{REQUEST_URI}.html [NC,L]
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteRule ^(.*)$ https://www.example.com/$1 [QSA,L,R=301]
    
    <FilesMatch "\.(woff)$">
    Header unset Vary
    </FilesMatch>
    
    <FilesMatch "\.(eot)$">
    Header unset Vary
    </FilesMatch>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-09
      • 2016-07-28
      • 2016-03-07
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      相关资源
      最近更新 更多