2011-11-02 127 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]