mod_rewrite的错误310 TOO_MANY_REDIRECTS [英] Mod_Rewrite Error 310 TOO_MANY_REDIRECTS

查看:2037
本文介绍了mod_rewrite的错误310 TOO_MANY_REDIRECTS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使pretty的URL(contact.php ID =东西联系/东西吗?)这code在.htaccess,但是当我用它我的浏览器显示错误310 - 过多的重定向

I want make pretty URL (contact.php?id=something to contact/something) with this code in .htaccess, but when I use it my browser displays error 310 - too many redirects.

Options +FollowSymlinks

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^contact/(.*)$ contact.php?id=$1 [L]

RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^contact.php$ /contact/%1? [R,L]

有人可以帮我,有什么不好? 谢谢。

Can somebody help me, what is wrong? Thanks.

推荐答案

您的问题是,要重定向联系人/到contact.php然后重定向contact.php联系(见的无限循环?)

You problem is that you are redirecting contact/ to contact.php then redirecting contact.php to contact (see the infinite loop ?)

要解决这个问题,你可以只添加一个无用的参数,以第一条规则(另一件事是,你应该使用R = 301在过去的规则,而不是仅仅R标志,这意味着重定向是您永​​久而不是暂时的,而是这不是造成任何问题):

To fix this you can just add another useless parameter to the first rule (another thing is that you should use R=301 in the last rule instead of just R flag, this mean that the redirection is permanant and not temporary, but that's not causing any issue) :

Options +FollowSymlinks

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^contact/(.*)$ contact.php?id=$1&r=0 [L]

RewriteCond %{QUERY_STRING} ^id=([^\&]*)$
RewriteRule ^contact.php$ /contact/%1? [R=301,L]

这篇关于mod_rewrite的错误310 TOO_MANY_REDIRECTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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