我想用一些RewriteRule
s到變換:預防規則,htaccess的重寫規則衝突
http://example.com/blah =>
index.php?id=blah
http://example.com/someone/blah =>
index.php?id=blah&user=someone
這裏htaccess
:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?id=$1 [L]
RewriteRule ^(.*)/(.*)$ /index.php?id=$2&user=$1 [L]
</IfModule>
但似乎最後兩個規則不兼容:這種htaccess
,我得到一些500 Internal Server Error
。
如何創建兩條規則,使它們不會相互「重疊」?
注:
每個這條規則單獨工作
當我使用第二個規則,然後http://example.com/someone/blah =>
index.php?id=blah&user=someone
作品,但似乎根文件夾不再是/
但/someone/
,然後找不到CSS ...在這種情況下如何防止基礎文件夾被更改?
+1出色答卷具有很好的解釋 – anubhava 2014-10-08 16:50:03
非常感謝你,現在對我來說更加清晰! – Basj 2014-10-08 19:07:04
更一般的(這裏沒有具體說明),你將如何添加一個後備?即'如果所有列出的條件都不滿足,則轉到url /' – Basj 2014-10-08 20:04:45