使用.htaccess重定向到子文件夹

时间:2013-07-24 06:45:50

标签: .htaccess

我的网络服务器上有以下DocumentRoot结构:

folder1
folder2

我可以用标准方式访问所有这些

my.ip.address.here/folder1
my.ip.address.here/folder2

我想将请求重定向到没有指定特定文件夹的网站到一个默认文件夹,即'folder1'。例如,如果我输入浏览器my.ip.address.here,它会将我重定向到'my.ip.address.here/folder1'。 我的.htaccess文件位于DocumentRoot文件夹中,其中包含以下内容:

RewriteEngine On
RewriteRule ^$ /folder1 [R=301, L]

当我在浏览器中运行网站时,我得到以下错误:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

配置有什么问题? 提前谢谢!

1 个答案:

答案 0 :(得分:0)

如果你想简单地想要在内部重定向,或者不/folder2这些规则中的任何一个。

使用规则重定向301:

RewriteRule ^$ /folder2 [R=301,L]

内部网址不会更改:

RewriteRule ^$ /folder2 [L]

如果您想要临时重定向,请使用302;使用301进行永久重定向。