隐藏.htaccess中的扩展名

时间:2011-04-20 11:02:14

标签: .htaccess

大家好 我有一个问题,我的文件有.html扩展名但我希望当文件在浏览器中打开时,扩展名有hidden.e.g file.html来存档。 提前谢谢

4 个答案:

答案 0 :(得分:5)

.htaccess文件中使用此代码:

RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteCond %{REQUEST_FILENAME}\.html -f  
RewriteRule ^(.*)$ $1.html

现在您可以使用http://www.mysite.com/contact而不是http://www.mysite.com/contact.html这样的邮件。

希望这有帮助!

答案 1 :(得分:1)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

示例 yoursite.com/wallpaper.html到yoursite.com/wallpaper /

答案 2 :(得分:0)

您的链接必须如下

<a href="example">Example</a>
 Instead of
<a href="example.php">Example</a>

然后将其添加到.htaccess文件

 RewriteCond ^example example.php [L]

答案 3 :(得分:0)

重写发动机 RewriteCond%{REQUEST_FILENAME}!-d
RewriteCond%{REQUEST_FILENAME} .html -f
RewriteRule ^(。*)$ $ 1.html

这个可以在一个网站中进行单个扩展。我在同一个网站上使用多个扩展名,例如index.html和contact.php。

我如何使用此代码?