使用htaccess重定向整个站点 [英] Redirect entire site using htaccess

查看:57
本文介绍了使用htaccess重定向整个站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用htaccess将整个网站及其所有页面/URL重定向到新站点?

How do I redirect an entire website and all of its pages/urls to a new site using htaccess?

当我尝试以下操作时,它仅将旧站点的主页重定向到新站点.

When I tried the below, it only redirected the home page of the old site to the new site.

重定向301/http://www.newsite.com

当我尝试以下操作时,首页被重定向,但是旧站点上的其他页面( www.oldsite.com/register )获得了404.

When I tried the below, the home page was redirected, but the other pages (www.oldsite.com/register) on the old site got 404.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldsite\.com$
RewriteRule ^/?$ "http\:\/\/www\.newsite\.com\" [R=301,L]

例如:

www.oldsite.com-> www.newsite.com

www.oldsite.com --> www.newsite.com

www.oldsite.com/register-> www.newsite.com

www.oldsite.com/register --> www.newsite.com

www.oldsite.com/images/cats-> www.newsite.com

www.oldsite.com/images/cats --> www.newsite.com

推荐答案

据我了解,您需要将旧域中的所有内容重定向到新域中的索引页面,因此以下代码应该为您工作:

as i understand you need to redirect every thing in old domain to just index page in new domain , so The following code should work for you:

RewriteEngine On
RewriteRule ^(.*)$ http://www.NEWDOMAIN.com [R=301,L]

这篇关于使用htaccess重定向整个站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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