后端开发|php教程
php asp jsp 301重定向的代码
后端开发-php教程
168彩票开奖网源码,ubuntu不能拖入文件,tomcat登陆数据库,保险爬虫技术,php论坛用的什么框架,dz板块seolzw
介绍一下针对各类程序系统实施301重定向的代码:
1、Linux主机重定向
Godaddy的Liunx主机,Godaddy本身已经支持Apache,所以直接创建一个.htaccess文件就可以了,一般来说,在本地无法创建.htaccess的时候可以先创建一个txt格式文件,上传到根目录的时候再重命名为“.htaccess”就可以了。网上很多如何进行 301重定向的教学,无论是整站重定向还是单页重定向。下面就以我的为例
1.1 无www域名转移到www域名
RewriteEngine on
rewritecond %{http_host} ^ [nc]
rewriterule ^(.*)$ /$1 [r=301,nc]
1.2 整站301重定向
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$ /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$ /$1 [L,R=301]
仿小米官网php源码,ubuntu内核回滚,tomcat8运行时,腾讯微博爬虫,php网站开发学习交流,宁夏seo讲师lzw
另外一种是在根目录下的index.php里这样弄
手机生活服务类源码,ubuntu 950m,爬虫怎么抢商品,php 西部数码,seo站内视频lzw
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location:/”);
exit();
2、ASP主机301重定向
在 index.asp 或 default.asp 的最顶部加入以下几行:
代码如下:
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”,” ”
Response.End
%>
3、主机301重定向
ASP .NET:
Response.Status = “301 Moved Permanently”;
Response.AddHeader(”Location”,””);
}
我封装在一个类里:
using System;using System.Collections.Generic;using System.Text;using System.Web.UI;using System.Web.UI.HtmlControls; namespace ClassLib{ public class URLClass { private bool flag301 = false;//是否启动 301 private bool isIndex = false;//是否 返回主页 或者保留在当前页 /// /// 是否启动 301 /// Page /// 格式 public URLClass(bool fl, Page page, string strURL) { flag301 = fl; URL301(page, strURL); } /// /// /// 格式 public void URL301(Page page, string strURL) { //301重定向 if (page.Request.Url.DnsSafeHost != strURL && flag301 == true) {page.Response.Clear();page.Response.StatusCode = 301;page.Response.Status = "301 MovedPermanently";page.Response.AddHeader("Location", "http://" + strURL);page.Response.End(); } } }}
1 2 3 下一页