Apache 301使用.htaccess从旧域重定向到新域
有old.test.ru和test.ru两个域。如何将所有页面从old.test.ru/*重定向到test.ru/* 我有这些。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),
<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/
如果要重定向所有请求,我将使用onold.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
重定向,因为它已经被关闭了。请查看我提供的链接,并在那里进行了解释.Isold.test.ru
只是test.ru
的一个别名
?它也不起作用-有一个错误:在此页面上,发现了循环转发。您必须清除重写规则
,该规则将old.test.ru
重写为htaccess
文件中的test.ru
nd%{HTTP_HOST}^old\.test\.ru$[或]
。不明白它的意思吗?我假设您在httpd.conf
中为old.test.ru
设置了一个
或类似的.htaccess
重定向,因为它已经被关闭了。请查看我提供的链接,并在那里进行了解释.Isold.test.ru
仅是test.ru
的别名
?的可能重复