URL重写:CSS,JS和图像不加载 [英] URL rewriting : css, js, and images not loading

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

问题描述

我下面的规则的.htaccess

Options +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]

RewriteRule ^detail/([0-9]+)/?$ detail.php?id=$1

重定向的http://本地主机/细节/ 123 网​​址的http://localhost/detail.php ID = 123 。页面重定向成功,但问题是 CSS,JS和图像不加载,

It redirects http://localhost/detail/123 URL to http://localhost/detail.php?id=123. The page redirects successfully, but the problem is CSS, JS, and images are not loading,

CSS,JS文件位于的http://本地主机/ CSS / 的http://本地主机/ JS /

CSS, js files are located under http://localhost/css/ and http://localhost/js/

一种解决方案是使用绝对路径(前/ CSS或/ JS,而不是仅仅的CSS /,/ JS但这似乎不是一个可靠的解决方案,因为我们已经在所有更改文件,

One solution is to use absolute path (ex /CSS, or /js rather than just CSS/, /js but this does not seem a reliable solution since we've to change it on all files,

根据的.htaccess 规则,任何其他解决办法,这是独立编辑的所有PHP文件,让我们用相对路径的?

Any other solution based on .htaccess rules, which is independent of editing all PHP files and let us use "relative paths"?

推荐答案

不要偷懒,改变你的相对URI在你的资源。这是最好的。

Don't be lazy and change your relative URIs in your resources. This is the best.

您可以弄巧,并使用正则表达式和替换所有你需要这将是像一些单行的文件,你就大功告成了。有多少地方可能有改变?你应该使用的模板。

You can get clever and use regex and replace all the files you need which would be like a few one liners and you're done. How many places could there be to change? And you should be using a template.

这应该工作,但我不会走这条路。

This should work but I wouldn't go this way.

重写规则^细节/(CSS | JS |图片)(。*)?/ $ / $ 1 / $ 2 [L,QSA,R = 301]

这篇关于URL重写:CSS,JS和图像不加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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