CSS和JS无法使用mod_rewrite加载 [英] CSS and JS not loading with mod_rewrite

查看:67
本文介绍了CSS和JS无法使用mod_rewrite加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用apache的mod_rewrite模块将我的URL结构(对于一个实例-www.mydomainname.com/user.php?u=somename)改进为一些喜欢的URL,例如www.mydomainname.com/user/somename.在遇到CSS和JS相对路径问题这一非常糟糕的情况之前,我已经成功实现了它. 每当我打开www.mydomainname.com/user/somename时,只要没有文本和基本HTML,它就可以成功地在没有CSS和JS的情况下加载.我使用了chrome的检查元素"功能,该功能可以帮助我了解发生的以下错误.

I am using apache's mod_rewrite module to improve my URL structure(for one instance- www.mydomainname.com/user.php?u=somename) to some fancy URL like www.mydomainname.com/user/somename . I have successfully achieved it until I got into this very bad situation of CSS and JS relative path issue. Whenever I open up www.mydomainname.com/user/somename, it loads successfully without CSS and JS with only text and basic HTML. I used chrome's "inspect element" feature, which help me to know the following errors that occurred.

GET http://www.mydomainname.com/user/css/style.css 404 (Not Found) somename:5
GET http://www.mydomainname.com/user/css/developer.css 404 (Not Found) somename:6
GET http://www.mydomainname.com/user/js/jquery-1.5.2.js 404 (Not Found) somename:7
GET http://www.mydomainname.com/user/js/jquery.form.js 404 (Not Found) somename:5

.htaccess文件具有以下内容-

The .htaccess file has following contents-

DirectoryIndex index.html.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule    ^user/([^/.]+)/?$    user.php?u=$1    [L]

user.php位于父文件夹以及CSS和JS文件夹中.我知道原因,但不知道如何清除错误.

The user.php is residing in the parent folder as well as the CSS and JS folders. I got to know the cause but do not know how to remove the errors.

编辑:user.php文件中给出的CSS和JS的路径是-

EDIT: The path of CSS and JS given in the user.php file are-

<link type = "text/css" rel = "stylesheet" href = "css/style.css">
<link type = "text/css" rel = "stylesheet" href = "css/developer.css">
<script type="text/javascript" src="js/jquery-1.5.2.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>

推荐答案

尝试添加绝对路径(只需在URL的开头添加/):

Try adding absolute paths (just add / at the beginning of the URL):

<link type = "text/css" rel = "stylesheet" href = "/css/style.css">
<link type = "text/css" rel = "stylesheet" href = "/css/developer.css">
<script type="text/javascript" src="/js/jquery-1.5.2.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>

这篇关于CSS和JS无法使用mod_rewrite加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆