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
Php .htaccess-将domain2.com重定向到domain1.com/folder,而不更改url_Php_.htaccess_Redirect - Fatal编程技术网

Php .htaccess-将domain2.com重定向到domain1.com/folder,而不更改url

Php .htaccess-将domain2.com重定向到domain1.com/folder,而不更改url,php,.htaccess,redirect,Php,.htaccess,Redirect,我有两个域名。比如说domain1.com和domain2.com。 我的主要网站运行在domain1.com上。 我想在domain1.com/blog上运行一个博客,但我想使用domain2.com作为此博客的url 我目前在.htaccess文件中有: RewriteCond %{HTTP_HOST} ^domain2.com RewriteRule ^(.*) http://domain1.com/blog [P] 这是可行的,但当我进入domain2.com时,url会更改为doma

我有两个域名。比如说domain1.com和domain2.com。
我的主要网站运行在domain1.com上。
我想在domain1.com/blog上运行一个博客,但我想使用domain2.com作为此博客的url

我目前在
.htaccess
文件中有:

RewriteCond %{HTTP_HOST} ^domain2.com
RewriteRule ^(.*) http://domain1.com/blog [P]
这是可行的,但当我进入domain2.com时,url会更改为domain2.com/blog,我只希望domain2.com不带/blog

我已经找了一个多小时了,找不到正确的解决办法

有什么想法吗?

试试这个:

RewriteCond %{HTTP_HOST} domain2.com
RewriteRule ^(.*)$ http://domain1.com/blog/$1 [L]

尝试在您的根目录中使用此选项
。htaccess

RewriteEngine On
RewriteRule ^$ blog/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ blog/$1
这将占用
domain2.com/blog
,并使生成的URL显示
domain2.com
,但仍将内容加载到
/blog
文件夹中

在测试之前,请确保清除缓存