在我们日常维护网站的过程中经常会遇到,使用一个域名跳转到另一个域名,这里给出几个方案。
1、使用301/302重定向的方法
301:永久性重定向
302:临时重定向
Linux系统解决办法:
Linux系统可以借助宝塔面板来解决
宝塔面板--网站--域名--设置--301重定向,填写目标URL,勾选启用301
WIndows IIS管理器
IIS管理器--网站--HTTP重定向--301--填写目标URL
第二种方法,修改网站根目录.htaccess文件(Linux)或者web.config文件(windows)来实现
RewriteEngine On RewriteBase / RewriteRule http://要跳转的域名/$ http://要转向的域名/ [R=301,L] RewriteRule ^(.*)article/list_([0-9]+).html$ $1/article/list_$2 [R=301,L]
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="rule1" stopProcessing="true"> <match url="^news/list_([0-9]+)" /> <action type="Rewrite" url="index.php?m=content&c=index&a=lists&catid=1&page={R:5}" /> </rule> <rule name="WWW Redirect" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{HTTP_HOST}" pattern="^需要转的域名$" /> </conditions> <action type="Redirect" url="http://要转到的域名/{R:0}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
通过域名解析的方法
域名解析添加CNAME记录,记录值伪目标网站URL,这样访问之后会直接跳转
通过网页代码跳转
在网页里面加入跳转代码实现跳转
html标签跳转:<meta http-equiv="refresh" content="1" url="http://www.web315.net/">
js跳转:
<script type="text/javascript">
window.location.href = "http://www.web315.net/";
</script>
后端跳转,以PHP为例:
<?php //重定向浏览器 header("Location: https://www.web315.net/"); //确保重定向后,后续代码不会被执行 exit; ?>
文章评论