2014-11-08 92 views
2

我已經成功地實現像URL基本的Facebook:mod_rewrite的()太多的內部重定向

http://example.com/(username)使用下面的mod_rewrite代碼內部調用http://example.com/sites/(username)

Options +FollowSymLinks 
RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !^/sites/ 
RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [NC,L] 

請注意(用戶名)文件夾存在於網站文件夾內

上述工作非常好。但現在我想美化我的其他網址,如: http://example.com/(username)/Image/2/這應該在內部調用http://example.com/sites/(username)/index.php?type=image&id=2

要做到這一點,我添加在倒數第二行下面的代碼:

RewriteRule ^([^/]+)/Image/(.*)$ /sites/$1/index.php?type=image&id=$2 [NC,L] 

我希望在[L]最終會在這之後停止計算規則。但是從日誌中可以看出它進入了一個無限循環並被截斷。

有人能指出我在這裏做錯了嗎?

回答

0

內成爲文檔的文件夾,你可以有這樣的.htaccess:

Options +FollowSymLinks 
RewriteEngine on 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule^- [L] 

RewriteRule ^([^/]+)/([^/]+)/(\d+)/?$ sites/$1/index.php?type=$2*id=$3 [QSA,L] 

RewriteRule ^((?!sites[^/]+)(/.*)?$ sites/$1$2 [NC,L]