2012-10-17 92 views
1

我想在我的網站上隱藏文件擴展名。
這是我.htaccess內容:如何在網站中隱藏文件擴展名?

# Do not remove this line, otherwise mod_rewrite rules will stop working 
RewriteBase/

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

例如:

http://example.com/website2將映射到http://example.com/website2.html

回答

0

製作WEBSITE2一個文件夾,並把你的命名爲index.html的在它的HTML。

+0

這種方法將工作,但絕對不是接近這一目標的最佳途徑。 – Timothy

0

在您的示例中,http://example.com/website2不會映射到任何內容,因爲沒有結尾斜槓。你的規則的正則表達式是^([^/]+)/$,需要一個尾部斜線。

所以你需要改變所有的鏈接http://example.com/website2.htmlhttp://example.com/website2/

爲了重定向你沒有任何控制權的鏈接,你可以添加以下規則:

RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)\ /(.*)\.html 
RewriteRule^/%1/ [L,R=301] 
+0

謝謝,這是非常有益的,工作很好。 – user1752627