2015-09-07 54 views
-1

我現在的.htaccess文件是:的.htaccess:刪除.html和添加結尾斜線

## Go Daddy servers need the Options -MultiViews code below 
 
Options -MultiViews 
 
RewriteEngine On 
 
RewriteBase/
 

 
# Remove .html extension 
 
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.html 
 
RewriteRule (.*)\.html$ /$1/ [L,R=301] 
 

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

 
# Force trailing slash 
 
RewriteCond %{REQUEST_FILENAME}.html -f 
 
RewriteRule .*[^/]$ $0/ [L,R=301]

但是,當我訪問一個頁面,它說:「所請求的URL/SomePage的/在這個服務器上沒找到。」我將如何解決這個問題?

回答

0

試試這個:

Options -Multiviews 
RewriteEngine On 
RewriteBase/

#Remove .html extension 
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC] 
RewriteRule^%1/ [NC,L,R] 

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

這條規則從文件中刪除HTML擴展,並在文件名的末尾添加一個tralling斜線。

在Apache 2.4上測試

+0

嗯,它似乎從頁面中刪除了CSS和資產。 – mannyrothman

+0

如果css是問題,那麼在你的文檔頭部添加** ** – starkeen

+0

像這樣:https://gist.github.com/fcpwiz/d19c67012193c5a57dd4? – mannyrothman