htaccess在文件夹的末尾添加index.htm

时间:2013-04-02 11:34:30

标签: .htaccess

我需要一种方法在url的末尾添加index.htm 例如:
www.example.com/folder1/folder2和
www.example.com/folder1/folder2/
必须在内部重定向到www.example.com/folder1/folder2/index.htm(这必须适用于任意数量的文件夹/子文件夹)
到目前为止,我的htaccess(从根本上)看起来像:

Options +FollowSymLinks
RewriteEngine on
RewriteOptions inherit
RewriteBase /

#
# some 301 REDIRECTS here
#


# rewrite non-www into www
# after all redirection rule AND before any rewrite rule
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]



#
# rewrite rules below here
#

有什么方法可以解决这个问题吗? 谢谢。

修改
  - 所有网址都来自重写规则 - 网站中没有实际的文件夹   - 在我的浏览器中键入www.example.com/folder1/folder2,只能找到404页面。我需要它重定向到www.example.com/folder1/folder2/index.htm(有一个创建此网址的规则)

2 个答案:

答案 0 :(得分:1)

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.htm$ [NC]
RewriteRule ^(.*?)/?$ /$1/index.htm [L,R=301]

答案 1 :(得分:0)

您的意思是要将/folder1/folder1/重定向到/folder1/index.htm,将/folder1/folder2/folder1/folder2/重定向到/folder1/folder2/index.htm和{{ 1}}和/folder1/folder2/folder3/folder1/folder2/folder3/

/folder1/folder2/folder3/index.htm