Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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,我正在尝试将旧域中的所有网页转到具有相同文件结构的新域中的相应网页。我正在使用下面的代码,但问题是旧网页转到索引网页,而不是相应的网页。基本上,我认为捕获url其余部分的(*)在重写规则中没有与$1一起显示 Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com(.*) [NC] RewriteRule ^ ht

我正在尝试将旧域中的所有网页转到具有相同文件结构的新域中的相应网页。我正在使用下面的代码,但问题是旧网页转到索引网页,而不是相应的网页。基本上,我认为捕获url其余部分的(*)在重写规则中没有与$1一起显示

 Options +FollowSymLinks -MultiViews
 RewriteEngine On
 RewriteBase /
 RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com(.*) [NC]
 RewriteRule ^ http://www.newdomain.com$1 [R=301,L]

如果使用
$1
,则需要使用
()
在重写规则中捕获某些内容。 试试这个:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
这将重定向
http://olddomain.com/page.php
http://www.newdomain.com/page.php

此外,如果可能存在多个
olddomain
s,请重定向不在
newdomain
的任何url:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^(www\.)?newdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
这将重定向
http://notnewdomain.com/page.php
http://www.newdomain.com/page.php

编辑:

以下是我的测试截图:

更近,但它会将文件夹放下。示例:转到而不是它也重定向
http://example.com/folder/page.php
http://www.newdomain.com/folder/page.php
。这就是你的意思吗?它不会帮我放下文件夹的。我已经包括了我的测试截图。在这里尝试:记住在更改
htaccess
文件后重新启动apache。