今天我試圖編寫一個.htaccess文件第一次爲了從url欄刪除.html擴展名以及一些我想做的事情。由於我不熟悉這一切,因此在編碼之前閱讀了幾篇文章。htaccess的錯誤
我結束了以下代碼。我也從所有鏈接中刪除了.html。問題是,當訪問我的域時,我得到以下錯誤。
//The resource you are looking for has been removed,
//had its name changed, or is temporarily unavailable.
我的代碼是否正確?
修訂的.htaccess
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
//Remove .html UNTIL NOW THIS IS THE ONLY PART
//OF THE CODE THAT ACTUALLY WORKS.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
//Caching schema
<FilesMatch "\.(jpg|png)$">
Header set Cache-Control "private, max-age=160704000"
</FilesMatch>
//Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
在一個單獨的.htaccess
//Prevent directory listings
Options All -Indexes
主要誤差 如果我點擊喜歡的鏈接:
<a href="index">Home</a>
然後我得到同樣的錯誤。
謝謝大家提前。
您的回答成功了嗎? – Legionar
我正在處理它:) – Mdermez
請參閱https://stackoverflow.com/questions/1992183/how-to-hide-the-html-extension-with-apache-mod-rewrite – joksnet