URL 重写问题未加载 .css [英] URL rewrite issue not loading .css

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

问题描述

我正在将一个旧站点移植到一个新模板,并且在使用 Windows 2008 重写模块时遇到了问题.我试图重写的链接如下所示:

I'm porting an old site to a new template and am having problems with the Windows 2008 rewrite module. The link I'm trying to rewrite looks like this:

http://ltweb2008.serveronline.net/product.php?pID=75

并调出页面就好了.然后我应用新的 URL 并加载正确的内容,但不再加载模板的 style.css 文件.

and brings up the page just fine. Then I apply the new URL and it loads the proper content, but doesn't load the template's style.css file anymore.

http://ltweb2008.serveronline.net/product/75/any-text-here

问题似乎是制作模板(画布)的公司将主要的 .css 文件放在根目录中,但将所有其余文件加载到/css 中.现在我无法使用 rewrite 加载主 .css 文件,当我将其向下移动到/css 时,它只显示一个 空白页面,不过当我查看页面源代码时,它就在那里.

The problem seems to be that the company who made the template (canvas) put the main .css file in the root directory, but loaded all the rest in /css. Now I can't get the main .css file to load using the rewrite and when I move it down to /css it only displays a blank page, though when I check out the page source it's all there.

有了这个页面显示但不使用 style.css(重写):

With this the page shows but is not using style.css (with rewrite):

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

使用这些中的任何一个,页面都是完全空白的(重写):

With any of these the page is completely blank (with rewrite):

  1. <link rel="stylesheet" href="/style.css" type="text/css"/>
  2. <link rel="stylesheet" href="/css/style.css" type="text/css"/>
  3. <link rel="stylesheet" href="http://ltweb2008.serveronline.net/style.css" type="text/css"/>

我将它用于模式:

^product/([0-9]+)/([^/]+)$

和重写 URL:

/product.php?pID={R:1}

有人知道我错过了什么吗?

Does anyone know what I'm missing?

推荐答案

一种解决方案是使用绝对路径(例如/css 或/js 而不仅仅是 css/、/js 但这看起来不是一个可靠的解决方案,因为我们必须在所有文件上更改它,

one solution is that use absolute path (ex /css, or /js rather than just css/, /js but this is not looks a reliable solution since we've to change it on all files,

这是因为您的相对 URI 的基址已更改.本来,页面是/product.php?id=75时的base是/,浏览器用/正确填写相对链接> 基地.但是当浏览器进入一个像 /product/75/any-text-here 这样的页面时,base 突然变成了 /product/ 并且它试图把它附加到所有的前面相对 URL,因此它们都不会加载.

This is because your relative URIs have their base changed. Originally, the base is / when the page is /product.php?id=75, and the browser properly fills in relative links with the / base. But when the browser goes to a page like /product/75/any-text-here the base suddenly becomes /product/ and it tries to append that in front of all relative URLs and thus none of them load.

您可以将链接设为绝对链接,也可以更改页面标题中的 URI 基础(在 <head> </head> 标记之间):

You can either make your links absolute, or change the URI base in the header of your pages (inbetween the <head> </head> tags):

<base href="/">

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

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