当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 利用404错误页面实现UrlRewrite的实现代码

Javascript
js操作ajax返回的json的注意问题!
javascript document.compatMode兼容性
jquery 锁定弹出层实现代码
Jquery+CSS 创建流动导航菜单 Fluid Navigation
js下用层来实现select的title提示属性
JSON 学习之JSON in JavaScript详细使用说明
jquery实现的超出屏幕时把固定层变为定位层的代码
jQuery 性能优化手册 推荐
javascript Firefox与IE 替换节点的方法
ext combox 下拉框不出现自动提示,自动选中的解决方法
json-lib出现There is a cycle in the hierarchy解决办法
判断控件是否已加载完成的代码
javascript for循环设法提高性能
js 表格拖拽效果实例代码 (IE only)
javascript 命名规则 变量命名规则
js 面向对象的技术创建高级 Web 应用程序
User agent字符串将成为用户真正的隐私问题
JS教程:JavaScript全半角转换
JS教程:Chrome对数组的sort方法优化
WEBJX收集非常有用的免费的Javascript开发工具

Javascript 中的 利用404错误页面实现UrlRewrite的实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 84 ::
收藏到网摘: n/a

要求:网站编码为utf-8,不适用于GB2312; 替换字符的正则可以自己增加和修改,以适合自己的网站; 将下面代码保存到err404.html,然后设置404错误页面为err404.html页;
复制代码 代码如下:

<script type="text/javascript" language="javascript">
var id=/(detial|show)\.asp\?id\=([0-9]+)/gi;
var flag=/([a-z0-9_]+)\.asp\?flag\=xml/gi;
var re_id=/(detial|show)\_([0-9]+)\.html/gi;
var re_flag=/([a-z0-9_]+)\.rss/gi;
var host='blog.ii-home.cn';
var ss=window.location.href;
//ss=ss.replace(window.location.hostname,host);
var Temp=getasp(ss);
getNotice(Temp);
function createobj() {
if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
}
function getNotice(url) {
var oBao=createobj();
var my_url=url;
oBao.open('get',my_url,false);
oBao.onreadystatechange=function(){
if(oBao.readyState==4){
if(oBao.status==200){
var returnStr=oBao.responseText;
var Temps=gethtml(returnStr);
document.write(Temps);
}else{
document.write("未找到您输入的地址或服务器505错误!");
}
}
}
oBao.send(null);
}
//将str中的asp网址按照正则替换
function gethtml(str){
var Temp_str=str.replace(id,'$1_$2.html');
Temp_str=Temp_str.replace(/index\.asp/gi,'index.html');
Temp_str=Temp_str.replace(/myfiles\.asp/gi,'myfiles.html');
Temp_str=Temp_str.replace(/mydiary\.asp\?typ\=self/gi,'mydiary_self.html');
Temp_str=Temp_str.replace(/mydiary\.asp/gi,'mydiary.html');
Temp_str=Temp_str.replace(flag,'$1.rss');
Temp_str=Temp_str.replace(/xml_diary\.asp/gi,'xml_diary.html');
Temp_str=Temp_str.replace(/xml_download\.asp/gi,'xml_download.html');
Temp_str=Temp_str.replace(/xml_links\.asp/gi,'xml_links.html');
Temp_str=Temp_str.replace(/xml_ly\.asp/gi,'xml_ly.html');
Temp_str=Temp_str.replace(/ly\.asp/gi,'ly.html');
//Temp_str=Temp_str.replace(/href=\"(http){0}/gi,'href="http://blog.ii-home.cn/');
return(Temp_str);
}
//将URL替换成原地址
function getasp(str){
var Temp_str=str.replace(re_id,'$1.asp?id=$2');
Temp_str=Temp_str.replace(/index\.html/gi,'index.asp');
Temp_str=Temp_str.replace(/myfiles\.html/gi,'myfiles.asp');
Temp_str=Temp_str.replace(/mydiary\.html/gi,'mydiary.asp');
Temp_str=Temp_str.replace(/mydiary\_self.html/gi,'mydiary.asp?typ=self');
Temp_str=Temp_str.replace(/xml_diary\.html/gi,'xml_diary.asp');
Temp_str=Temp_str.replace(/xml_download\.html/gi,'xml_download.asp');
Temp_str=Temp_str.replace(/xml_links\.html/gi,'xml_links.asp');
Temp_str=Temp_str.replace(/xml_ly\.html/gi,'xml_ly.asp');
Temp_str=Temp_str.replace(/ly\.html/gi,'ly.asp');
Temp_str=Temp_str.replace(re_flag,'$1.asp?flag=xml');
return(Temp_str);
}
</script>
"