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

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
Apache 301使用.htaccess从旧域重定向到新域_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 301使用.htaccess从旧域重定向到新域

Apache 301使用.htaccess从旧域重定向到新域,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,有old.test.ru和test.ru两个域。如何将所有页面从old.test.ru/*重定向到test.ru/* 我有这些。htaccess: <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteBase / # redirect from index.(php|asp|aspx|html|htm), main.(php|asp|aspx|html|htm),

有old.test.ru和test.ru两个域。如何将所有页面从old.test.ru/*重定向到test.ru/*

我有这些。htaccess:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   RewriteEngine On
   RewriteBase /

   # redirect from index.(php|asp|aspx|html|htm), main.(php|asp|aspx|html|htm), home.(php|asp|aspx|html|htm)
   RewriteRule ^(.*)index\.(php|asp|aspx|html|htm)$ $1 [R=301,L]
   RewriteRule ^(.*)main\.(php|asp|aspx|html|htm)$ $1 [R=301,L]
   RewriteRule ^(.*)home\.(php|asp|aspx|html|htm)$ $1 [R=301,L]

   # redirect from dev and www
   RewriteCond %{HTTP_HOST} ^old\.test\.ru$ [OR]
   RewriteCond %{HTTP_HOST} ^www\.test\.ru$
   RewriteRule ^(.*)$ http://test\.ru/$1 [R=301,NC]
</IfModule>
但不适用于:

old.test.ru/some/about.php -> test.ru/some/about.php
old.test.ru/some1/company.php -> test.ru/some1/company.php
old.test.ru/some2/contact.php -> test.ru/some2/contact.php
old.test.ru/some2/subsome/contact.php -> test.ru/some2/subsome/contact.php
我应该更改什么?

如果要重定向所有请求,我将在
old.test.ru
上使用,而不是使用
mod\u rewrite

old.test.ru的配置中,使用:

Redirect permanent / http://test.ru/
如果要重定向所有请求,我将使用on
old.test.ru
而不是
mod\u rewrite

old.test.ru的配置中,使用:

Redirect permanent / http://test.ru/

尝试用以下内容替换上一条规则:

 # redirect from dev and www
 RewriteCond %{HTTP_HOST} ^(www|old)\.test\.ru$ [NC]
 RewriteRule ^ http://test.ru%{REQUEST_URI} [R=301,L]
更新:从URL中删除
index.php
等:

 RewriteCond %{HTTP_HOST} ^(www|old)\.test\.ru$ [NC]
 RewriteRule ^(.*?)((?:index|default)\.(?:php|html?))?$ http://test.ru/$1 [R=301,L,NC]

尝试用以下内容替换上一条规则:

 # redirect from dev and www
 RewriteCond %{HTTP_HOST} ^(www|old)\.test\.ru$ [NC]
 RewriteRule ^ http://test.ru%{REQUEST_URI} [R=301,L]
更新:从URL中删除
index.php
等:

 RewriteCond %{HTTP_HOST} ^(www|old)\.test\.ru$ [NC]
 RewriteRule ^(.*?)((?:index|default)\.(?:php|html?))?$ http://test.ru/$1 [R=301,L,NC]

不幸的是,它不起作用。。。现在,即使使用old.test.ru重定向到test.ru也停止工作…请确保将此代码放在任何其他规则之前。另外,请告诉我您的Apache版本是什么?服务器版本:Apache/2.2.23(FreeBSD)服务器构建时间:2012年11月10日20:55:13好的,将此代码放在
RewriteBase
行的正下方,并在另一个浏览器中测试。.htaccess:
Options+FollowSymLinks-RewriteBase/RewriteRule^(.*)index\(php | asp | aspx | html | htm)$$1[R=301,L]RewriteRule^(.*)main\.(php | asp | aspx | html | htm)$$1[R=301,L]RewriteRule^(.*)home\.(php | asp | aspx | html | htm)$$1[R=301,L]#从dev和www RewriteCond%{HTTP|HOST}^dev test ru ru ruhttp://test\.ru/$1[R=301,北卡罗来纳州]
不幸的是,它不起作用…现在甚至可以使用old.test.ru重定向到test.ru停止工作…请确保将此代码放在任何其他规则之前。还要告诉我您的Apache版本是什么?服务器版本:Apache/2.2.23(FreeBSD)服务器构建:2012年11月10日20:55:13好的,将此代码放在
RewriteBase
行的正下方,并在不同的浏览器中测试..htaccess:
Options+FollowSymLinks RewriteEngine On RewriteBase/RewriteRule^(.*)index\(php | asp | aspx | html | htm)$$1[R=301,L]RewriteRule^(.*)main\(php | asp | aspx | html | htm)$$1[R=301,L]RewriteRule]^(.*)home\.(php | asp | aspx | html | htm)$$1[R=301,L]#从dev和www RewriteCond%{HTTP_HOST}^dev\.test\.ru$[或]RewriteCond%{HTTP_HOST}^www\.test ru$RewriteRule^(.$)http://test\.ru/$1[R=301,北卡罗来纳州]
它也不起作用-有一个错误:在这个页面上,发现了循环转发。你必须清除你的
重写规则
,在你的
.htaccess
文件中将
old.test.ru
重写为
test.ru
重写cond%{HTTP\u HOST}^old\.test\.ru$[OR]
。不明白它的意思吗?我假设您在
httpd.conf
中为
old.test.ru
设置了一个
或类似的
.htaccess
重定向,因为它已经被关闭了。请查看我提供的链接,并在那里进行了解释.Is
old.test.ru
只是
test.ru
的一个
别名
?它也不起作用-有一个错误:在此页面上,发现了循环转发。您必须清除
重写规则
,该规则将
old.test.ru
重写为
htaccess
文件中的
test.ru
nd%{HTTP_HOST}^old\.test\.ru$[或]
。不明白它的意思吗?我假设您在
httpd.conf
中为
old.test.ru
设置了一个
或类似的
.htaccess
重定向,因为它已经被关闭了。请查看我提供的链接,并在那里进行了解释.Is
old.test.ru
仅是
test.ru
别名
?的可能重复