url 重写 deosnt 访问我的 css 和图像?为什么

发布于 2024-09-27 20:44:08 字数 399 浏览 0 评论 0原文

我的 url 有这个重写规则,它似乎无法访问 css 和图像,为什么? :))

原始网址其工作:

http://www.example.co.uk/viewprofile.php?user=muna

重写的网址,此 deosnt 工作:

http://www.example.co.uk/user/muna

htaccess 代码:

RewriteEngine On
RewriteRule ^user/([^/]*)$ /viewprofile.php?user=$1 [L]

我的 css 文件存储在 /css 文件夹中,图像存储在 /images 文件夹中

i have this rewrite rule for my urls, it deosnt seem to acess the css and images, why? :))

orginal url its working:

http://www.example.co.uk/viewprofile.php?user=muna

rewrited url, this deosnt work:

http://www.example.co.uk/user/muna

htaccess code:

RewriteEngine On
RewriteRule ^user/([^/]*)$ /viewprofile.php?user=$1 [L]

my css files are stored in /css folder and images in the /images folder

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

時窥 2024-10-04 20:44:08

抱歉,我找到了解决方案,我将回答这个问题只是为了将来为其他 stackoverflowers 提供参考,基本上,当您对任何 url 进行重写时,只需确保您以正确的方式链接到 javascript、css 或图像,例如:

如果在之前你有:

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

然后更改为:

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

在 css 文件夹名称之前引用额外的 / 。谢谢希望有帮助

sorry guys, i found the solution, im gonna answer this question just for future reference for other stackoverflowers, basically when you do a rewrite on any url just make sure when your linking to javascripts, css or images the right way for example:

if before you had:

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

then change to this:

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

quote the extra / before css folder name. thanks hope it helps

旧时浪漫 2024-10-04 20:44:08

或者你可以添加一些规则,然后你可能不需要更改html代码。

RewriteRule ^user/css/(.*)$ /css/$1 [L]

or you can add some rules, and then you may don't need change the html code.

RewriteRule ^user/css/(.*)$ /css/$1 [L]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文