2011-12-19 60 views
0

好吧,所以我創建了一個用戶可以創建配置文件的網站。我希望用戶配置文件像http://example.com/username,但問題是它與其他規則衝突。現在htacess URL重寫URL中的用戶名與其他重寫的URL衝突

RewriteEngine on 
Options +FollowSymLinks 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule story/(.*)/ story.php?id=$1 
RewriteRule story/(.*) story.php?id=$1 

#Profiles: 
RewriteRule (.*)/ profile.php?id=$1 
RewriteRule (.*) profile.php?id=$1 

,什麼情況是,當我試圖訪問http://example.com/story/hello_world系統認爲,在URL「故事」是數據庫的用戶名和搜索,然後拋出404頁(如預期)。

我不希望像example.com/user/username這樣的用戶頁面。

例子:Digg.com有digg.com/story和digg.com/username

回答

0

可以更換兩個與下面的規則,你的規則,以防止問題http://example.com/story/hello_world被解釋爲一個用戶。

RewriteRule ^([^/])+/?$ profile.php?id=$1 [L] 

如果您對用戶名有更具體的規定,例如,用戶名是字母數字,長度在5-10個字符之間,則更好的規則是

RewriteRule ^([a-zA-Z0-9]{5,10})/?$ profile.php?id=$1 [L]