【问题标题】:htaccess Redirects Not Working Righthtaccess 重定向无法正常工作
【发布时间】:2015-02-12 10:03:55
【问题描述】:

我的网页 URL 应该以 https://www 开头。我的一些重定向无法正常工作。我要举的例子是:

romancestuck.com/aboutus/amycunningham.htm

应该重定向到:

https://www.romancestuck.com/aboutus.htm

但它却陷入了重定向循环。

我的 .htaccess 文件中的代码是:

RewriteEngine On
RewriteBase /

### REDIRECT NON-WWW TO WWW - START ###
  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301]
### REDIRECT NON-WWW TO WWW - END ###

### REDIRECT NON-HTTPS TO HTTPS - START ###
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
### REDIRECT NON-HTTPS TO HTTPS - END ###

redirect 301 /aboutus/amycunningham.htm https://www.romancestuck.com/aboutus.htm

任何帮助将不胜感激!

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    像这样重构你的规则:

    RewriteEngine On
    
    RewriteRule ^aboutus/amycunningham\.htm$ https://www.romancestuck.com/aboutus.htm [L,NC,R=302]
    
    ### REDIRECT NON-WWW TO WWW & REDIRECT NON-HTTPS TO HTTPS ###
    RewriteCond %{HTTP_HOST} !^www\. [OR]
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://www.romancestuck.com%{REQUEST_URI} [R=302,L,NE]
    

    记得在新的浏览器中测试或在测试前清除浏览器缓存。

    一旦您确认它工作正常,请将R=302 替换为R=301。在测试你的 mod_rewrite 规则时避免使用R=301(永久重定向)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-08
      • 2013-11-04
      • 2023-04-02
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      • 2020-01-16
      相关资源
      最近更新 更多