mod_rewrite RewriteRule的重定向循环错误

时间:2011-11-02 19:05:40

标签: php .htaccess mod-rewrite

我正在尝试mod_rewrite:

localhost/edit.php?title=?&user_id=?

要:

localhost/edit/<?php echo $title.'/'.$user_id; ?>

因此,我可以将链接作为循环输出

echo '<a href="localhost/edit/'.$title.'/'.$user_id.'">'.$title.'</a>';

我正在使用:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
#Reroute through index.php
    RewriteRule ^([a-zA-Z0-9_]+) index.php?title=$1 [NC]

#this is RewriteRule for edit.php UPDATED:
    RewriteRule ^/?edit/([a-zA-Z0-9_]+)/([0-9]+)$ edit/index.php?title=$1&user_id=$2 [NC,L]

然而,我收到此错误:
此网页有重定向循环

1 个答案:

答案 0 :(得分:2)

试试这个

Options +FollowSymLinks
RewriteEngine On

# /edit/title_here/123 -> edit.php?title=title_here&user_id=123
RewriteRule ^edit/([A-Za-z0-9_]+)/([0-9]+)$ edit.php?title=$1&user_id=$2 [NC,L]

#Reroute through index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9_]+) index.php?title=$1 [NC,L]