为什么我的简单重写代码会导致重定向循环?

时间:2011-10-19 02:01:55

标签: apache .htaccess mod-rewrite

如果有人能帮助我完成这项工作,我将非常感激。

我正在尝试将domain.com/painting.php?name=hello重定向到domain.com/page/hello,同时保持重写:

RewriteCond %{QUERY_STRING} name=([^&]+) 
RewriteRule ^painting\.php$ /page/%1? [R=301,L] #redirects to page
RewriteRule ^page/([^/\.]+)/?$ painting.php?name=$1 [L] #rewrites painting

我想只保留“漂亮的网址”。请帮忙。

在这里找到答案:simple 301 redirect with variable not working, why?

1 个答案:

答案 0 :(得分:1)

我假设您真正想要做的是能够接受URL domain.com/page/hello并将其(无形地)重写为domain.com/painting.php?name=hello。如果是这样,试试这个

RewriteRule ^page/([^/.])+/?$ painting.php?name=$1 [QSA,L]
相关问题