html - 使用 mod_rewrite 后,我的 css imges js 路径发生了变化

标签 html css apache .htaccess mod-rewrite

我已经更改了我的网址

http://example.com/course.php?id=1001

http://example.com/course/1001

但在更改所有 css js 和图像的 url 后,它不起作用

我用过这段代码

RewriteEngine On
RewriteRule ^course/([A-Za-z0-9-]+)/?$ coursedetails.php?id=$1 [NC,L]

最佳答案

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 的基础已更改。最初,基数是 /当页面为 /course.php?id=1001 , 并且浏览器正确填写了带有 / 的相关链接根据。但是当浏览器转到类似 /course/1001 的页面时基地突然变成/course/它会尝试将其附加到所有相对 URL 的前面,因此它们都不会加载。

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

<base href="/">

关于html - 使用 mod_rewrite 后,我的 css imges js 路径发生了变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31212900/

相关文章:

javascript - 当在 jquery.menu-aim 中打开父菜单时,强制子菜单可见

apache - Cloudflare 通过 https,服务器上没有端口 443

jquery - 根据屏幕尺寸将选择下拉列表转换为列表

jQuery 更改悬停类的属性

html 追加文本值以形成 Action

html - CSS全屏背景图片尺寸

c++ - 从 Apache 正在运行的 C++ 代码调用 bash 脚本的权限问题

apache - 301 重定向根查询字符串?

javascript - JS 中的径向形状

html - 如何使用 Flexbox 以 Angular 并排对齐 2 个不同的组件