2014-06-10 81 views
1

我的.htaccess:如何使.htaccess規則不被覆蓋?

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 

RewriteRule ^product-([^/]+).html$ index.php?tid=$1 [L] 
RewriteRule ^links-([^/]+).html$ index.php?page=links&lid=$1 [L] 

RewriteRule ^([^/]+).html$ index.php?page=$1 [L] 

問題:

如果我把對主站點的目錄文件test.html它變得不可見。

如果我改變我的htaccess文件規定:

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 

RewriteRule ^([^/]+).html$ index.php?page=$1 [L] 

RewriteRule ^product-([^/]+).html$ index.php?tid=$1 [L] 
RewriteRule ^links-([^/]+).html$ index.php?page=links&lid=$1 [L] 

我在URL /product-10.html 404錯誤,但test.html可用。

如何在這兩種情況下,它的工作這樣做(的test.html必須是可用的,如果存在,產品-10.html必須重定向到的index.php?TID = 10)?

回答

1

首先忽略單獨規則中的所有實際文件和目錄。

使用此代碼:

RewriteEngine On 

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

RewriteRule ^product-([^/]+)\.html$ index.php?tid=$1 [L,QSA] 

RewriteRule ^links-([^/]+)\.html$ index.php?page=links&lid=$1 [L,QSA] 

RewriteRule ^([^/]+)\.html$ index.php?page=$1 [L,QSA] 
+0

哇!它真的很有用。謝謝! – xercool

+0

很高興知道,您是否可以通過點擊答案左上角的刻度線來將答案標記爲已接受。 – anubhava