htaccess规则不完美

时间:2013-11-03 10:35:12

标签: php regex apache .htaccess mod-rewrite

我的htaccess规则不起作用 我不想显示php扩展
我的规则

Options +FollowSymlinks -MultiViews -Indexes  
RewriteEngine on  
RewriteBase /  
RewriteRule ^WHMCS/?$ 404.php [L]  
RewriteRule .*\.php$ 404.php [L]       
RewriteRule ^contact$ /contact.php  [L]
RewriteRule ^p/([a-zA-Z0-9_-]+)/?$ ./page.php?page=$1 [L] 
RewriteRule ^comments$ ./comments.php [L]  

但是当我打开网址而没有任何扩展时,它也显示我404错误
提前谢谢

1 个答案:

答案 0 :(得分:0)

注释掉此规则:RewriteRule .*\.php$ 404.php [L]并在规则结束时使用此规则:

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]