使用mod_rewrite后,我的CSS imges js的路径被改变我的、路径、mod_rewrite、CSS

2023-09-02 09:54:07 作者:积攒一身酷

我已经改变了我的网址,从

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

  http://example.com/course/1001
 

但改变所有的CSS js和图片的URL后无法正常工作

我用这个code

  RewriteEngine叙述上
重写规则^当然/([A-ZA-Z0-9  - ] +)?/ $ coursedetails.php ID = $ 1 [NC,L]
 
l4d2附件怎么启用 MOD什么的

解决方案   

1的解决方案是使用绝对路径(前/的CSS,或/ JS,而不是仅仅的CSS /,/ JS但这不是看起来可靠的解决方案,因为我们已经在所有的文件改变它,

这是因为你的相对URI有自己的基地改变。原来,该基地是 / 页面时 /course.php?id=1001 ,并在浏览器正确填写与 / 基础相对链接。但是,当浏览器转到页像 /场/ 1001 基地突然变得 /场/ 键,它会尝试添加在所有相对URL的前面,因此他们没有加载。

您可以让您的链接是绝对的,或更改URI基地,在网页的标题(插图中的< HEAD>< /头> 标签):

 <基地的HREF =/>
 

I have changed my url from

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

To

http://example.com/course/1001

but after changing the url of all the css js and images is not working

I have use this code

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,

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

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="/">