简易url跳转代码
HTML型:
<script>
location.href="http://liutingdong.cn/post-307.html";
</script>
ASP型:
<%
response.redirect "http://liutingdong.cn/post-274.html"
%>
PHP型:
<?php
Header("Location: http://liutingdong.cn/post-321.html");
?>
相关编程语言的301跳转代码
一、ASP.Net 301跳转代码
<script runat="server">
private void Page_Load(object sender,System.EventArgs e){
Response.Status =“301 Moved Permanently”;
Response.AddHeader("Location",“url”);
}
</script>
二、PHP301永久跳转代码
header("HTTP/1.1 301 Moved Permanently");
header("Location: URL");
exit();
三、CGI Perl301跳转代码
$q = new CGI;
print $q->redirect("URL");
四、JSP301永久跳转代码
<%
response.setStatus(301);
response.setHeader("Location", "URL");
response.setHeader("Connection", "close");
%>
五、Apache服务器创建.htaccess文件做301跳转代码(需要开启mod_rewrite)
1、将顶级域名跳转到www域名,代码:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^liutingdong.cn [NC]
RewriteRule ^(.*)$ www.liutingdong.cn$1 [L,R=301] 2)
2、将一个域名重定向到另一个域名,代码:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ URL$1 [L,R=301] 3)
3、使用正则表达式进行301转向,实现伪静态,代码:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$news.php?id=$1
上述代码可以将news.php?id=1这样的网址转向到news-123.html
六、Apache下vhosts.conf中配置301跳转
将顶级域名跳转到带www的域名,vhosts.conf中配置为:
<VirtualHost *:80>
ServerName www.liutingdong.cn
DocumentRoot
</VirtualHost>
<VirtualHost *:80>
ServerName liutingdong.cn
RedirectMatch permanent ^/(.*) URL$1
</VirtualHost>
七、IIS7下webconfig文件中配置301跳转带代码<?xml version="1.0" encoding="UTF-8"?><configuration><system.webServer><rewrite><rules><rule name="WWW Redirect" stopProcessing="true"><match url=".*" /><conditions><add input="{HTTP_HOST}" pattern="^lanecat.com$" /></conditions><action type="Redirect" url="http://www.liutingdong.cn/{R:0}" redirectType="Permanent" /></rule></rules></rewrite></system.webServer></configuration>
默认分类 2021-03-31 09:45:26 通过 网页 浏览(811)
共有0条评论!