如何制作.htaccess规则不会被覆盖?

时间:2014-06-10 07:50:40

标签: apache .htaccess mod-rewrite

我的.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]

我在网址/product-10.html中有404错误,但test.html可用。

如果在两种情况下都可以这样做( test.html 必须可用,如果存在且product-10.html必须重定向到 index.php?tid = 10 )?

1 个答案:

答案 0 :(得分: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]
相关问题