.htaccess将根目录重定向到子文件夹

时间:2014-11-13 15:47:16

标签: apache .htaccess redirect

使用.htaccess我正在尝试将站点根目录的请求重定向到子目录。我试过的三种方法都失败了,或者留下了不可取的东西。

无效递归失败:

Redirect / http://example.org/sub

这些似乎不适用于默认的index.html:

Redirect / http://example.org/sub/index.html
Redirect /index.html http://example.org/sub/index.html

这样可行,但将目录保留在顶层,这需要重写html文件中的相对链接:

DirectoryIndex http://example.org/sub/index.html

那么,有没有直接的方法将根完全重定向到子文件夹并让一切都在那里工作?我试图避免.htaccess的更高级功能 - 如果它太复杂,我可能只是更喜欢第三种选择。

1 个答案:

答案 0 :(得分:1)

在旧网站的DocumentRoot中有这样的规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} !example\.org$ [NC]
RewriteRule ^ http://example.org/sub%{REQUEST_URI} [L,NE,R=301]
相关问题