2014-06-10 139 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