Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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_Url_Redirect_Url Rewriting_Subdomain - Fatal编程技术网

.htaccess 将域重定向到目录,同时保留地址

.htaccess 将域重定向到目录,同时保留地址,.htaccess,url,redirect,url-rewriting,subdomain,.htaccess,Url,Redirect,Url Rewriting,Subdomain,我有两个域(example.com和example2.com)指向同一个位置。我想将其中一个域(example2.com)重定向到目录(example.com/dir),而不发生以下任何情况: 地址栏显示example.com/dir 地址栏显示example2.com,但不加载example.com/dir的内容,而不是index.html example.com也重定向到example.com/dir 以便: example2.com显示example.com/dir example2

我有两个域(
example.com
example2.com
)指向同一个位置。我想将其中一个域(
example2.com
)重定向到目录(
example.com/dir
),而不发生以下任何情况:

  • 地址栏显示
    example.com/dir
  • 地址栏显示
    example2.com
    ,但不加载
    example.com/dir
    的内容,而不是
    index.html
  • example.com
    也重定向到
    example.com/dir
以便:

  • example2.com
    显示
    example.com/dir
  • example2.com/page.html
    显示文件
    example.com/dir/page.html

提前感谢

,鉴于两个域都指向同一文档根,那么您应该能够使用此规则将
example2.com
重写为
/dir

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com [NC]
RewriteRule ^(.*)$ /dir/$1 [L]
如果不是这样,并且它们不在同一台服务器上,则必须使用
mod proxy
[p]
来完成此任务。这将出现在example2.com.htaccess上

RewriteEngine On
RewriteRule ^(.*)$ http://example.com/dir/$1 [P]