infinite loop while using modwrite in htaccess

陌路散爱 提交于 2019-12-13 06:22:10

问题


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

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]

回答1:


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.

Try this instead:

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]


来源:https://stackoverflow.com/questions/21578126/infinite-loop-while-using-modwrite-in-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!