Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
Apache mod_rewrite将主机重定向到另一个文件夹_Apache_Mod Rewrite - Fatal编程技术网

Apache mod_rewrite将主机重定向到另一个文件夹

Apache mod_rewrite将主机重定向到另一个文件夹,apache,mod-rewrite,Apache,Mod Rewrite,我有一些域都重定向到同一个文件夹(my public_html)。我想编写一个.htaccess文件,将每个域发送到它自己的文件夹中(因此不会在导航栏上显示)。 例如,导航到将加载我的服务器的文件夹/public\u html/example.com/ 在另一个上下文中,我使用了以下代码: RewriteCond %{HTTP_HOST} example\.com$ [NC,OR] RewriteRule ^(.*)$ http://www.anotherdomain.com/$1 [R=301

我有一些域都重定向到同一个文件夹(my public_html)。我想编写一个.htaccess文件,将每个域发送到它自己的文件夹中(因此不会在导航栏上显示)。 例如,导航到将加载我的服务器的文件夹
/public\u html/example.com/

在另一个上下文中,我使用了以下代码:

RewriteCond %{HTTP_HOST} example\.com$ [NC,OR]
RewriteRule ^(.*)$ http://www.anotherdomain.com/$1 [R=301,L]
但现在我不想重定向到另一个域;我只想从另一个文件夹获取文件


这是可以实现的吗?提前感谢。

用以下内容替换现有内容:

RewriteCond %{REQUEST_URI} !^/%{HTTP_HOST}/ [NC]
RewriteRule ^(.*)$ /%{HTTP_HOST}/$1  [L]

对于显式主机重定向:

RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} !^/example.com/
RewriteRule ^(.*)$ /example.com/$1  [L]

RewriteCond %{HTTP_HOST} otherexample\.com [NC]
RewriteCond %{REQUEST_URI} !^/abc/otherexample.com/public_html
RewriteRule ^(.*)$ /abc/otherexample.com/public_html/$1  [L]

但是我可以明确地说我想重定向“example.com”吗?假设example.com将从
/public\u html/example.com/
获取文件,但otherexample.com将导致
/public\u html/abc/otherexample.com/public\u html
…是的,您可以进行显式的主机->目录映射,查看我的编辑行为与我期望的完全相同。非常感谢。