url rewrite重写后前台的html页面的相关css,js文件找不到路径的解决方法

配置url rewrite重写url路径之后,在对前台html页面进行渲染的时候,会丢失对css,js等相对目录的应用。
具体解决方法如下:
在<head></head>之间加上<base href=<%=webpath%>/>标签。
比如:
1:urlrewrite.xml
 
<span style="white-space: pre;"> </span><rule>
        <span style="white-space: pre;"> </span><from>/category/([0-9]+)</from>
        <span style="white-space: pre;"> </span><to>/article.jsp?act=list&amp;id=$1</to>
    <span style="white-space: pre;"> </span></rule>
在访问article.jsp页面的时候如果此页面有相关的css,js,图片等的相对目录的引用,最简单的办法就是在<head>标签之间加上当前网站目录的<base>标签。这样就不会找不到目录了
 
<%@ include file="taglib.jsp"%>
<%  
string path = request.getcontextpath();  
string basepath = request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/";  
%>
 
<html>
<head>
<span style="white-space: pre;"> </span><base href="<%=basepath%>">
</head>
<body>
<span style="white-space: pre;"> <div class="zhongjian1"><img src="images/home/sk.jpg" /></div></span>
</body>
</html>
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值