这是我的.htaccess
。它将/contact
重定向到index.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?
如果URL中有.php
,例如contact.php
,则加载正常的.php
页面。
我怎么能这么做?
在rewriterrule:
RewriteCond %{REQUEST_FILENAME} !-f
-f表示"是一个文件"。使用此规则,您的意思是"请求的文件名不是一个存在的文件"(在DocumentRoot, ofc中)。
更多信息和选项:http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond