Problem with / in htaccess file rule and the page load
I have this url: http://mysite.com/content/14
and this line in htaccess file:
RewriteRule ^content\/([^-]+)$ index.php?m=apple&id=$1 [L,NC,NS]
It works OK and show the right page, but with no CSS and JS. CSS & JS files don't load. It is because the src
of JS files and href
of CSS files don't start with /
. They are too ma开发者_如何学Cny and I can't fix them.
Is there anyway to fix it with some codes in htaccess without need to change other files?
The problem is that the client (you browser) thinks that the resource is located on http://mysite.com/content/14
, making relative URLs resolve to http://mysite.com/content/
. However, the file is served from http://mysite.com/
.
If you cannot change the references, you may be able to put in a <base>
tag (in the HTML — chances are that you can't do that either):
<base href="http://mysite.com/" />
This goes in the <head>
section.
Alternatively, make a rewrite for CSS and JS (untested):
RewriteRule ^content\/(js|css)\/(.+)$ $1/$2 [L]
精彩评论