的.htaccess URL重写问题(脚本不加载) [英] .htaccess URL Rewrite Problem (Scripts don't load)

查看:228
本文介绍了的.htaccess URL重写问题(脚本不加载)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在.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的<事项的根/ code>从浏览器中隐藏。因此,将要求的文件:

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

这篇关于的.htaccess URL重写问题(脚本不加载)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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