URL 重写后缺少 CSS 文件和图像

Missing CSS file and images after URL rewrite(URL 重写后缺少 CSS 文件和图像)
本文介绍了URL 重写后缺少 CSS 文件和图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用模式重写制作用户友好的 URL.我的问题是,在为我的 URL 提供名称"之类的类别后,当我使用新 URL 调用页面时,它无法加载 CSS 文件或图像.

I'm trying to make user friendly URL using mode rewrite. My problem is, that after giving category like 'name' to my URL, when I call the page using new URL, it can't load the CSS file or images.

我有一个链接:

localhost/mywebsite/project?id=22

localhost/mywebsite/project?id=22

新链接类似于

localhost/mywebsite/project/22/myproject.project

localhost/mywebsite/project/22/myproject.project

htaccess 代码:

htaccess code:

RewriteRule ^project/([0-9]*)/.*.project$ /project.php?project=$1 [L]

(它可能不是 100% 正确,但我现在无法访问我的代码,所以我只是写了这个,它在原始源代码上运行良好)

(it might not be 100% right but I don't have access to my code right now so I just wrote this and it works fine on the original source)

我的根目录是 localhost/mywebsite/

My root directory is localhost/mywebsite/

我的 CSS 文件在 css/style.css

and my CSS file is in css/style.css

localhost/mywebsite/css/style.css

localhost/mywebsite/css/style.css

我的 htaccess

my htaccess

localhost/mywebsite/.htaccess

localhost/mywebsite/.htaccess

我的project.php文件在

and my project.php file is in

localhost/mywebsite/project.php

localhost/mywebsite/project.php

所以在项目页面中,我可以使用相对路径访问 CSS 文件,

So in the project page I have access to CSS file by using relative path,

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

但是当我使用重写的 URL 页面时找不到 CSS 文件.

but when I use rewritten URL page can't find the CSS file.

我还没有域名,所以不能使用绝对路径和域名!它可以是任何东西.

I can't use absolute path with domain name because I don't have domain yet! and it can be anything.

一种方法是按照类似问题的建议使用域的相对路径本地主机/我的网站/project.php当我在本地运行脚本时,我的根目录是本地主机所以css链接应该看起来像

one way is to use relative path to domain as suggested on the similar questions localhost/mywebsite/project.php and when i run my script localy my root directory is localhost so css link should look like

href="mywebsite/css/style.css"

href="mywebsite/css/style.css"

但是当我上线时,我应该将所有链接更改为可能类似于

but when i go live i should change all links to probably something like

href="/css/style.css"

href="/css/style.css"

这似乎有很多工作

推荐答案

为您的本地版本添加

<base href="//localhost/mywebsite" />

到头部部分

对于您的实时版本,请将其更改为

and for your live versions change it to

<base href="//your.domain.here" />

参考 http://www.w3.org/TR/html4/struct/links.html#h-12.4

这篇关于URL 重写后缺少 CSS 文件和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)