的.htaccess URL重写问题(脚本不加载)重写、脚本、加载、问题

由网友(10.流口水的云)分享简介:我有在.htaccess的URL重写问题的一个问题。I am having a problem with an URL rewrite issue in .htaccess.这是我的改写code RewriteEngine onRewriteBase /RewriteRule ^terms(.*) t...

我有在.htaccess的URL重写问题的一个问题。

I am having a problem with an URL rewrite issue in .htaccess.

这是我的改写code

RewriteEngine on
RewriteBase /

RewriteRule     ^terms(.*)  terms.php [L,nc]
RewriteRule ^formgate/([a-zA-Z0-9]{64,64})$ formgate.php?g=$1 [L,nc]

在页面加载的功能是否正常,只是我所有的样式表,JavaScript文件等不正常加载。如果您检查错误,它规定404没有发现和$没有定义。谢谢

When the page loads it functions properly except that all of my stylesheets, javascript files, etc do not load properly. If you check the errors it states 404 not found and that $ is not defined. Thanks

推荐答案

这个问题通常来自使用的相对URL的以样式表或JavaScript文件,并将其与虚拟目录结构相结合。如果你有一个重写这样的:

This problem often comes from using relative URL's to stylesheets or javascript files and combining it with a virtual directory structure. If you have a rewrite like this:

RewriteRule ^articles/(.*)$ articles.php

然后,你必须像一个网址:

Then you have a URL like:

http://example.com/articles/2011/03/14/title-of-the-article

包含HTML:

which contains the HTML:

<link rel="stylesheet" type="text/css" href="css/general.css" />

无论您的文件 artices.php 驻留在你的web目录的浏览器对此一无所知作为 mod_rewrite的从浏览器中隐藏。因此,将要求的文件:

no matter if your file artices.php resides in the root of your web directory the browser knows nothing about it as the matters of mod_rewrite are hidden from the browser. So it will ask for the file:

http://example.com/articles/2011/03/14/title-of-the-article/css/general.css

这显然不存在。所以,我建议指定的URL对于你的web根。例如:

which obviously does not exist. So I recommend specifying URL's relative to your web root. For example:

<link rel="stylesheet" type="text/css" href="/css/general.css" />

胸怀 / 在theURL面前。

Mind the / in front of theURL.

请注意以下事项:当您的URL开始以 / 字符表示相对路径的根的网页的一个。看看这个例子directurey结构:

Please note the following: when your URL starts with a / character it means a path relative to the root of the webpage. Check out this example directurey structure:

/
    /index.html
    /afolder
        /afolder/stylesheets
            /afolder/stylesheets/first.css
            /afolder/stylesheets/second.css
        /afolder/images
            /afolder/images/a.jpg
    /otherfolder
        /otherfolder/something.html