2012-02-29 173 views
0

後如何添加斜線如何使用刪除HTML擴展後,下面的代碼添加/結尾:刪除HTML擴展

Options +FollowSymLinks -MultiViews 
DirectorySlash off 

RewriteEngine On 
RewriteCond %{SCRIPT_FILENAME}/ -d 
RewriteCond %{SCRIPT_FILENAME}.html !-f 
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L] 

RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
RewriteRule ^(.+)\.html$ /$1 [R=301,L] 

RewriteCond %{SCRIPT_FILENAME}.html -f 
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L] 
+0

我幫不了你,但你應該更具體些:你應該說你在使用apache和mod重寫時存在問題(這只是一個猜測,但你應該首先告訴它),並添加正確的標記(像html,apache,mod-rewrite,文件擴展名應該這樣做)幫助人們幫助你...只是一個建議 – 2012-02-29 13:13:44

+0

感謝您的答覆e代碼更改以下網址http://www.example.co.uk/page.html到http://www.example.co.uk/page,我需要的是/在頁面結束後得到http:/ /www.example.co.uk/page/ – 2012-02-29 13:16:16

+1

請正確標記您的問題; 'html'等等,所以其他的與你的問題完全無關。 – 2012-02-29 13:19:00

回答

0

你需要做出一些改變。

Options +FollowSymLinks -MultiViews 

RewriteEngine On  
RewriteBase/

#Code to add forward slash 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(?:\.\w+|/)$ 
RewriteRule (.*) $1/ [R,L] 

#To check whether a .html appended string is a file existing on the system 
RewriteCond %{DOCUMENT_ROOT}/$1.html -f 
RewriteRule (.*)/ $1.html [L] 

#### NOT REQUIRED 
#RewriteCond %{SCRIPT_FILENAME}/ -d 
#RewriteCond %{SCRIPT_FILENAME}.html !-f 
#RewriteRule [^/]$ %{REQUEST_URI}/ [R,L] 

RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
RewriteRule ^(.+)\.html$ /$1 [R,L] 

而且根據需要這些規則將無法正常工作:

RewriteCond %{SCRIPT_FILENAME}.html -f 
RewriteRule [^/]+/$ %{REQUEST_URI}.html [QSA,L] 

COS,%{REQUEST_URI}總會有/末。如果一個URI像domain.com/about被請求,

它將改寫爲:

domain.com/about/ 

終於

domain.com/about/.html