htaccess重定向无法正常工作 [英] htaccess Redirects Not Working Right

查看:50
本文介绍了htaccess重定向无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页URL应该以 https:// www 开头。我的某些重定向无法正常工作。我将放置的示例是:

  romancestuck.com/aboutus/amycunningham.htm 

应重定向到:

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

,但卡在了重定向循环中。 / p>

.htaccess文件中的代码为:

  RewriteEngine On 
RewriteBase /

###将非WWW重定向到WWW-开始###
RewriteCond%{HTTP_HOST}!^ www\。
RewriteRule ^(。*)$ https://www.% {HTTP_HOST} / $ 1 [R = 301]
###重定向非万维网到万维网-结束###

###将非HTTPS重定向到HTTPS-开始###
RewriteCond%{HTTPS} off
RewriteRule(。*)https://%{HTTP_HOST}%{REQUEST_URI} [ R = 301]
###将非HTTPS重定向到HTTPS-结束###

重定向301 /aboutus/amycunningham.htm https://www.romancestuck.com/aboutus。 htm

任何帮助将不胜感激!

解决方案

像这样重构您的规则:

  RewriteEngine On 

RewriteRule ^ aboutus / amycunningham\.htm $ https://www.romancestuck.com/aboutus.htm [L,NC,R = 302]

###重定向非万维网至万维网将非HTTPS重定向到HTTPS ###
RewriteCond%{HTTP_HOST}!^ www\。 [OR]
RewriteCond%{HTTPS}关闭
RewriteRule ^ https://www.romancestuck.com% {REQUEST_URI} [R = 302,L,NE]

请记住在测试之前在新的浏览器中进行测试或清除浏览器缓存。



确认其运行正常后,将 R = 302 替换为 R = 301 。在测试您的mod_rewrite规则时,避免使用 R = 301 (永久重定向)。


My web page URLs should start with https://www. Some of my redirects are not working right. The example I will put is:

romancestuck.com/aboutus/amycunningham.htm

should redirect to:

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

but instead it gets stuck in a redirect loop.

The code in my .htaccess file is:

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

Any help would be greatly appreciated!

解决方案

Refactor your rules like this:

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]

Remember to test this in a new browser or clear browser cache before testing.

Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

这篇关于htaccess重定向无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆