0

这是我的.htaccess。它重定向/contactindex.php?page=contact
这完美地工作。但是有了这个.htaccess,如果有人放/contact.php,他们会得到一个错误。

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule ^([^/]+)/?$ index.php?page=$1  [QSA]

基本上,有没有办法只.php在 URL 中没有的情况下重写?
如果.phpURL 中有一个,例如contact.php只加载普通.php页面。

我怎么能这样做?

4

1 回答 1

2

在 RewriteRule 之前添加类似这样的内容:

RewriteCond %{REQUEST_FILENAME} !-f

-f 表示“是一个文件”。使用此规则,您是在说“请求的文件名不是现有文件”(在 DocumentRoot 中,ofc)。

更多信息和选项:http ://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond

于 2013-05-28T14:29:47.617 回答