2013-10-20 75 views
-4

我一直在努力清理我的網址與htaccess,但我不能看到讓它在我的本地主機上工作。localhost刪除HTML擴展

自己的網站網址:本地主機/ index.html的

這是默認htaccess文件,在我的WWW文件夾。

#------------------------------------------------------------------------------ 
# To allow execution of cgi scripts in this directory uncomment next two lines. 
#------------------------------------------------------------------------------ 

AddType application/x-httpd-php .html .htm .php 
AddHandler cgi-script .pl .cgi 
Options +ExecCGI +FollowSymLinks 
+0

請分享你的嘗試,以及他們的結果。即使他們不工作,他們告訴我們,你已經試圖自己解決這個問題,它可以讓我們知道出了什麼問題。參見[SO問題清單](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist)。 – Sumurai8

回答

2

在Web根目錄/www

Options +ExecCGI +FollowSymLinks -MultiViews 

RewriteEngine on 
RewriteBase/

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

現在http://localhost/page.html也可以作爲http://localhost/page訪問添加到您的.htaccess


請注意,我以前錯過了加入 RewriteCond %{REQUEST_FILENAME} !-d。這種情況可以確保任何現有名爲 /page的目錄都不會被 page.html覆蓋。

+1

+1,但我也會添加'RewriteCond%{REQUEST_FILENAME}!-d'條件 – anubhava

+1

@anubhava謝謝。更新。 –