将所有请求从旧域重定向到新域 [英] Redirect all request from old domain to new domain

查看:144
本文介绍了将所有请求从旧域重定向到新域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望从旧域迁移到新域。

I am looking to migrate from old domain to new domain.

我有我的旧域 olddomain.com 和新域 newdomain.com 暂时指向相同的IP地址。

I have my old domain olddomain.com and new domain newdomain.com pointing to same ip address for now.

我已经安装了Apache服务器来处理

I have Apache server inplace to handle requests.

我如何 301重定向我所有的

olddomain.com/*

&

www.olddomain.com/*

newdomain.com/*

我可以获取需要在 htaccess 中添加的确切正则表达式或配置。

Can I get exact regex or configuration that I need to add in htaccess.

我的newdomain.com和olddomain.com都由来自同一IP的同一apache服务器托管,因此 /重定向可能会导致循环?所以一直在寻找有效的方法

我尝试了

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^localhost$ [OR]
    #  RewriteCond %{HTTP_HOST} ^www.olddomain.com$
    RewriteRule (.*)$ http://comp16/$1 [R=301,L]
</IfModule>

甚至尝试添加虚拟主机

RedirectMatch (.*)\.jpg$ http://comp17$1.jpg 

但是当我在浏览器中按localhost到我的计算机名称即comp16时,它不会将站点重定向

But it does not redirect site when i hit localhost in browser to my computer name i.e comp16

推荐答案

在每个 olddomain.com 主机的配置( VirtualHost )中,尝试以下操作:

In the configuration (VirtualHost) for each of your olddomain.com host try this:

Redirect permanent / http://newdomain.com/

Apache重定向文档。这是应重定向所有内容时的首选方法。如果必须使用 mode_rewrite / htaccess ,那么在SO上会有很多问题,其中之一是:

Apache documentation for Redirect. This is the preferred way when everything should be redirected. If you must use mode_rewrite/htaccess there are plenty of questions around this on SO and one of them is:

如果第一个域具有文件夹路径,我如何301将一个域重定向到另一个域

编辑

Apache关于简单重定向的建议

mod_alias provides the Redirect and RedirectMatch directives, which provide a means to
redirect one URL to another. This kind of simple redirection of one URL, or a class of 
URLs, to somewhere else, should be accomplished using these directives rather than 
RewriteRule. RedirectMatch allows you to include a regular expression in your 
redirection criteria, providing many of the benefits of using RewriteRule.

这篇关于将所有请求从旧域重定向到新域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆