如何在$ htaccess的p $ pvent无限重定向循环? [英] How to prevent infinite redirect loop on htaccess?

查看:150
本文介绍了如何在$ htaccess的p $ pvent无限重定向循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的情况:
/sport.html 所有URL隐藏真实的URL /archive.php?action=search&section=sport

 #这个是规则:
重写规则^([A-ZA-Z _] +([A-ZA-Z0-9 _] +)?)( - ([0-9] +))\ HTML $ /archive.php?action=search&?。部分= $ 1 [L]
 

现在我想隐藏真实的URL和所有直接访问的页面 archive.php ,但我收到重定向循环错误此规则:

 重写规则^档案\的.php。* $ /404.html [F,NC,L]
 

解决方案

我想你实际上是在寻找的不是这样的:

 重写规则^档案\的.php。* $ /404.html [F,NC,L]
 

由于很明显,这将导致一个循环,因为你的第一条规则被改写为 archive.php ,并且该规则将其重写为别的,等等等等。

尝试,而不是上面的规则这样的:

 的RewriteCond%{THE_REQUEST} \ /archive\.php
重写规则^ /404.html [F,L]
 

或者,如果你想成为看中它:

 的RewriteCond%{THE_REQUEST} \ /archive\.php\?action=search&section =([^&放大器; \] +)
重写规则^ /%1.html [R,L]
 

I have this situation:
all urls like /sport.html hide the real url /archive.php?action=search&section=sport

#This is the RULE:
RewriteRule ^([a-zA-Z_]+([a-zA-Z0-9_]+)?)(-([0-9]+))?\.html$ /archive.php?action=search&section=$1 [L]

Now I want to hide the real url and all direct access to the page archive.php but I receive the redirect loop error with this rule:

RewriteRule ^archive\.php.*$ /404.html [F,NC,L]

解决方案

I think what you're actually looking for isn't this:

RewriteRule ^archive\.php.*$ /404.html [F,NC,L]

As obviously, this causes a loop, since your first rule is rewriting to archive.php, and this rule rewrites it to something else, etc. etc.

Try this instead of the above rule:

RewriteCond %{THE_REQUEST} \ /archive\.php
RewriteRule ^ /404.html [F,L]

Or, if you want to be fancy about it:

RewriteCond %{THE_REQUEST} \ /archive\.php\?action=search&section=([^&\ ]+)
RewriteRule ^ /%1.html [R,L]

这篇关于如何在$ htaccess的p $ pvent无限重定向循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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