2012-02-29 140 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