2011-11-02 175 views
0

我试图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] 

不过,我得到这个错误:
此网页有重定向循环

+0

是有唯一的规则?你有没有目录结构'edit/A-Za-z0-9 _ +/0-9 +'? – Shef

+0

是的。 RewriteRule ^([a-zA-Z0-9 _] +)index.php?title = $ 1 [NC]。这是通过index.php重定向页面。 – Graham

+1

请发布htaccess的所有内容,在不了解所有这些规则的情况下调试重写规则并不容易,尤其是它们的顺序。 – Shef

回答

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]