【发布时间】:2011-07-08 07:21:28
【问题描述】:
我在 htaccess 中写了下面的代码
重写规则 ^([a-zA-Z_-]+).php$ http://www.domain.com/myfile.php?page=inc-$1.php [NC]
我不想重写 index.php 文件 - 它应该正常打开。
【问题讨论】:
标签: .htaccess
我在 htaccess 中写了下面的代码
重写规则 ^([a-zA-Z_-]+).php$ http://www.domain.com/myfile.php?page=inc-$1.php [NC]
我不想重写 index.php 文件 - 它应该正常打开。
【问题讨论】:
标签: .htaccess
您可以使用以下代码来排除所有现有文件(如 index.php):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z_-]+).php$ http://www.domain.com/myfile.php?page=inc-$1.php [NC]
或仅排除 index.php 您可以使用:
RewriteCond %{REQUEST_URI} !^(.*/)?index\.php$ [NC]
RewriteRule ^([a-zA-Z_-]+).php$ http://www.domain.com/myfile.php?page=inc-$1.php [NC]
【讨论】:
!-index.php 无效。 -f 表示文件存在,!-f 表示文件不存在。
我认为这就是你要问的:
"我想允许 index.php 文件 正常送达,但所有其他 请求遵循此重写..."
为了防止索引文件被重定向,你需要在规则前加上一个 RewriteCond:
RewriteCond $1 !index\.php
RewriteRule ^([a-zA-Z_-]+).php$ http://www.domain.com/myfile.php?page=inc-$1.php [NC]
【讨论】: