2013-05-28 52 views
0

这是我的.htaccess。它重定向/contactindex.php?page=contact
这很好用。但有了这个.htaccess,如果有人把​​,他们会得到一个错误。.htaccess url重写

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

基本上,有没有什么办法,如果有在URL中没有.php只改写?
如果网址中有.php,例如contact.php只是加载正常.php页面。

我该怎么做?

+0

可能重复http://stackoverflow.com/questions/1698464/mod-rewrite-去除php-but-still-serve-the-php-file) – typeoneerror

回答

2

添加像这样的重写规则之前:

RewriteCond %{REQUEST_FILENAME} !-f 

-f意味着 “是一个文件”。有了这个规则,你说“请求的文件名不是一个现有的文件”(在DocumentRoot中ofc)。

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

[?MOD \ _rewrite删除.PHP但仍服务于PHP文件(的
+0

谢谢你!你能帮我做第二部分吗? –

+0

试试这个:'RewriteCond%{REQUEST_FILENAME}!\。php $ [NC]'(来源:http://stackoverflow.com/questions/1698464/mod-rewrite-to-remove-php-but-still-serve-在-PHP文件) –