在htaccess中使用modwrite时出现无限循环 [英] infinite loop while using modwrite in htaccess

查看:92
本文介绍了在htaccess中使用modwrite时出现无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该代码中要执行的操作是: 任何访客点击诸如 http://domain.com/article.php?id=44 .htaccess文件会将他转移到domain/article/44

What am trying to do in that code is: Any visitor click on an href like http://domain.com/article.php?id=44 the .htaccess will transfer him to domain/article/44

然后是另一个重写规则,以从文件article.php中获取请求的ID的内容.

then another rewrite rule to to get the content of requested id from the file article.php

RewriteCond %{QUERY_STRING} ^id=([^&]*)
RewriteRule ^article\.php$ http://alarabe.org/article/%1?
RewriteRule ^article/([a-z0-9\-]+)$ /article.php?id=$1 [L]

推荐答案

此规则不正确,肯定会导致循环.您需要使用THE_REQUEST变量,该变量代表Apache从浏览器收到的原始请求.

This rule isn't right and will certainly cause looping. You need to use THE_REQUEST variable that represents original request received by Apache from your browser.

尝试以下方法:

RewriteCond %{THE_REQUEST} \s/+article\.php\?id=([^\s&]+) [NC]
RewriteRule ^ http://alarabe.org/article/%1? [R=302,L]

RewriteRule ^article/([a-z0-9\-]+)$ /article.php?id=$1 [L]

这篇关于在htaccess中使用modwrite时出现无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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