ASP301永久跳转代码

ASP301永久跳转代码怎么写?SEO顾问潇湘驭文为您提供ASP301永久跳转代码、php301永久跳转代码等跳转代码。

顶级域名“wangyuwen.com”做权重可以传递的301永久跳转,转到一级域名“www.wangyuwen.com”。一来让网站权重更加集中,二来,保持一致性。

<%

currentdomain= request.ServerVariables(“SERVER_NAME”)

If currentdomain=”wangyuwen.com” or currentdomain=”http://wangyuwen.com” then

Response.Status=”301 Moved Permanently”

Response.AddHeader “Location”,”http://www.wangyuwen.com”

End if

%>

ASP Request

Request对象用于从用户那里取得信息。

request.ServerVariables

ServerVariables 集合用于取回服务器变量的值。

SERVER_NAME:返回服务器主机名、DNS别名,或者IP地址。

ASP Response

Response对象用于从服务器向用户发送输出的结果。

Response.Status:

Status 属性规定由服务器返回的状态行的值。

语法

response.Status=statusdescription(状态描述) 状态描述包括三位数的数字和对应代码的描述。这些都是在http定义。 比如【301 Moved Permanently】——301永久迁移。 比如【404 Not Found】——404不存在。

Response.AddHeader:

AddHeader 方法向 HTTP 响应添加一个新的 HTTP 头部和值。

注释:一旦头部被添加,就无法删除。

注释:在 IIS 4.0 中,调用此方法需要在任何输出送往浏览器之前。在 IIS 5.0 中,您可以在脚本中的任何点调用 AddHeader 方法,只要它先于对 response.Flush 方法的调用。

语法

response.AddHeader name,value name是必须的,是新头部变量的名称 (不能包含下划线)。 value也是必须的,是新头部变量的初始值。

相关编程语言的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} ^wangyuwen.com [NC]

RewriteRule ^(.*)$ www.wangyuwen.com$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.wangyuwen.com

DocumentRoot

</VirtualHost>

<VirtualHost *:80>

ServerName wangyuwen.com

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.lanecat.com/{R:0}” redirectType=”Permanent” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

 

免责声明:本文由用户上传,如有错误请指正,如有侵权请留言。

(0)
上一篇 2013 年 7 月 20 日 18:00
下一篇 2013 年 8 月 11 日 21:06

相关推荐

发表回复

登录后才能评论

评论列表(2条)