htaccess阻止页面扩展名显示

时间:2011-12-11 21:01:02

标签: php html .htaccess

我设置了htaccess文件,以便我的网站页面不需要显示扩展名,我的链接设置如下,最后是斜杠:

 www.mywebsite/about/

这些链接有效 - 但如果我直接输入

 www.mywebsite/about.html 

该网站将显示此页面的html扩展名。是否有一种方法可以阻止扩展显示,即使它们是直接输入的? :S

除了一个php页面外,我的大多数页面都是html。这就是我在htaccess中所拥有的:

Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)/$ $1.html [L]
RewriteRule ^php-page/([^/\.]+)/?$ php-page.php?p=$1 [L]

如果有人能帮助我,我会非常感激! :)

1 个答案:

答案 0 :(得分:0)

请试试这个:

Options -Indexes
Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^(.*)\.html$
RewriteRule .* %1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)/$ $1.html [L]

RewriteRule ^php-page/([^/\.]+)/?$ php-page.php?p=$1 [L]

我认为它可以做得比这更好,但它应该有效。

相关问题