Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用.htaccess重定向到子文件夹_.htaccess - Fatal编程技术网

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

使用.htaccess重定向到子文件夹,.htaccess,.htaccess,我的Web服务器上有以下DocumentRoot结构: folder1 folder2 我可以用标准方式访问所有这些文件 my.ip.address.here/folder1 my.ip.address.here/folder2 我想将请求重定向到未将特定文件夹指定为默认文件夹(即“folder1”)的网站。例如,如果我键入浏览器my.ip.address.here,它会将我重定向到“my.ip.address.here/folder1”。 我的.htaccess文件位于我的Document

我的Web服务器上有以下
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]
当我在浏览器中运行网站时,我会得到以下eror:

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.
配置可能有什么问题?
提前谢谢

如果您只想在内部重定向,或者不想将
/
重定向到
文件夹2
,则这些规则中的任何一条都可以

使用规则重定向301:

RewriteRule ^$ /folder2 [R=301,L]
在内部,URL不会更改:

RewriteRule ^$ /folder2 [L]

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

这是重复的,它不会将my.ip.address.here/folder1重定向到吗?我想,这与OP请求的行为不匹配。我想,OP只想重定向root,而不想重定向到folder2。是的,V-X是正确的。我想在没有任何路径的情况下重定向根目录到folder2。@Prix,如果我使用第一个选项-redirect 301//folder2,我会得到循环错误。