您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 来宾分类信息网,免费分类信息发布

asp.net php asp jsp 301重定向的代码

2025/3/4 5:34:06发布6次查看
介绍一下针对各类程序系统实施301重定向的代码:
1、linux主机重定向
godaddy的liunx主机,godaddy本身已经支持apache,所以直接创建一个.htaccess文件就可以了,一般来说,在本地无法创建.htaccess的时候可以先创建一个txt格式文件,上传到根目录的时候再重命名为“.htaccess”就可以了。网上很多如何进行 301重定向的教程,无论是整站重定向还是单页重定向。下面就以我的www.wecanwecan.com为例
1.1 无www域名转移到www域名
rewriteengine on
rewritecond %{http_host} ^wecanwecan.com [nc]
rewriterule ^(.*)$ http://www.wecanwecan.com/$1 [r=301,nc]
1.2 整站301重定向
options +followsymlinks
rewriteengine on
rewritecond %{http_host} ^wecanwecan.com [nc]
rewriterule ^(.*)$ http://www.wecanwecan.com/$1 [l,r=301]
rewritecond %{http_host} ^www.wecanwecan.com [nc]
rewriterule ^(.*)$ http://wecanwecan.com/$1 [l,r=301]
另外一种是在根目录下的index.php里这样弄
header(“http/1.1 301 moved permanently”);
header(“location:http://wecanwecan.com/”);
exit();
2、asp主机301重定向
在 index.asp 或 default.asp 的最顶部加入以下几行:
代码如下:
response.status=”301 moved permanently”
response.addheader “location”,”www.wecanwecan.com ”
response.end
%>
3、asp.net主机301重定向
asp .net:
response.status = “301 moved permanently”;
response.addheader(”location”,http://www.wecanwecan.com);
}
我封装在一个类里:
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 /// 格式www.xxx.com public urlclass(bool fl, page page, string strurl) { flag301 = fl; url301(page, strurl); } /// /// 返回主页 /// /// /// 格式www.xxx.com 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  下一页
来宾分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录