.htaccess将“/”添加到我的域中除domain.com之外的特定或所有文件夹

时间:2013-10-24 14:52:21

标签: apache .htaccess

我想在人们在浏览器网址上插入时:domain.com/foo重定向到domain.com/foo/(foo | bar | etc,是真正的文件夹)我读了这个.htaccess rewrite condition trailing slash only for specific directories 但我认为我的问题是apache,有些人说Apache把de slash放到文件夹但是有一个原因,不是我的,我现在该怎么办?
这是我的.htaccess

上的重定向行
RewriteBase /
RewriteEngine On

#without www 
RewriteCond %{HTTP_HOST} ^www.(.+)$  [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

#html to php
RewriteRule ^(.*)\.html$ $1.php [nc]

#index on folder
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/index.html [L]

*****************************************************
#this is the last rewrite I inserted trying to do so, without success
RewriteCond %{REQUEST_URI} ^/(foo|bar|etc)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
*****************************************************

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在根目录中尝试此代码.htaccess:

DirectorySlash On

RewriteBase /
RewriteEngine On

#without www 
RewriteCond %{HTTP_HOST} ^www.(.+)$  [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

*****************************************************
#this is the last rewrite I inserted trying to do so, without success
RewriteCond %{REQUEST_URI} ^/(foo|bar|etc)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
*****************************************************

#html to php
RewriteRule ^(.*)\.html$ $1.php [L,NC]

#index on folder
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/index.html [L]