使用htaccess重定向整个站点

编程入门 行业动态 更新时间:2024-10-23 15:24:52
本文介绍了使用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/www.newsite

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

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

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

例如:

www.oldsite-> www.newsite

www.oldsite --> www.newsite

www.oldsite/register-> www.newsite

www.oldsite/register --> www.newsite

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

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

推荐答案

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

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 ^(.*)$ www.NEWDOMAIN [R=301,L]

更多推荐

使用htaccess重定向整个站点

本文发布于:2023-11-01 17:52:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550006.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   站点   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!