各种301转向代码

一 IIS中实现301转向

1.打开internet信息服务管理器,在欲重定向的网页或目录上按右键

2.选中“重定向到URL”

3.在对话框中输入目标页面的地址

4.选中“资源的永久重定向”

5.点击“应用”即可生效

二 ASP下的301转向代码

   1. <%@ Language="VBScript" %>
   2. <%
   3. Response.Status = "301 Moved Permanently"
   4. Response.AddHeader "Location", "http //www url com"
   5. %>

三 PHP下的301转向代码

   1. <?
   2. header("HTTP/1.1 301 Moved Permanently");
   3. header("Location http //www url com");
   4. exit();
   5. ?>

 四 ASP.Net下的301转向代码

   1. <script runat="server">
   2. private void Page_Load(object sender, System.EventArgs e)
   3. {
   4. Response.Status = "301 Moved Permanently";
   5. Response.AddHeader("Location","http //www url com");
   6. }
   7. </script>

五 CGI Perl下的301转向代码

   1. $q = new CGI;
   2. print $q->redirect("http //www url com");

七 Apache下301转向代码

1)将不带WWW的域名转向到带WWW的域名下 

   1. Options +FollowSymLinks
   2. RewriteEngine on
   3. RewriteCond %{HTTP_HOST} ^url.com [NC]
   4. RewriteRule ^(.*)$ http //www url com/$1 [L,R=301]

   2)重定向到新域名 

    1. Options +FollowSymLinks
   2. RewriteEngine on
  3. RewriteRule ^(.*)$ http //www url com/$1 [L,R=301]

八 Apache下vhosts.conf中配置301转向

为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:

Apache下vhosts.conf中配置301转向

   1. <VirtualHost * 80>
   2. ServerName www url com
   3. DocumentRoot /home/lesishu
   4. </VirtualHost>
   5.

   6. <VirtualHost * 80>
   7. ServerName url.com
   8. RedirectMatch permanent ^/(.*) http //www url com/$1
   9. </VirtualHost>

九 Ruby中实现301转向

   1. def old_action
   2. headers["Status"] = "301 Moved Permanently"
   3. redirect_to "http //www url com"
   4. end

十 Coldfusion中实现301转向

1. <.cfheader statuscode="301" statustext="Moved permanently">
2. <.cfheader name="Location" value="http //www url com">

 

转载于:https://www.cnblogs.com/cdxkyz/archive/2013/03/17/2964565.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值