Jump to content

Mod_rewrite Ongoing Help Thread


chibineku
 Share

Recommended Posts

I am just fiddling with mod_rewrite in Apache and I've got it working, it's easy enough, but for some reason pages that have been rewritten display without any styles. It's most perplexing. Here is my rewrite rule:RewriteEngine On#Translate products/psorisis/chamomile-skin-cream-P[x] to productview.php5?id=1RewriteRule ^products/.*-P([0-9]+) /productview.php5?id=$1 [L]And here is a sample page:http://www.sinaesthesia.co.uk/products/-P2Anyone got any ideas why?

Edited by chibineku
Link to comment
Share on other sites

It's because it's searching for the stylesheet relative to the URL, and your URL has a lot of extra slashes in it before being rewritten.If you have a link to 'style.css', it will look for www.sinaesthesia.co.uk/products/-P2/style.cssThe best way to solve this is to make all your links relative to the root directory by putting a slash before them:'/style.css' or '/directory/style.css'

Link to comment
Share on other sites

Ah, okay, that makes sense. Well, actually, no: if I am using mod rewrite to turn the url products/-P1 into products.php5?id=1, say, which is the original URL that I developed with, surely the styles are found relative to that, as they always were? I mean, clearly they aren't, but why? As far as the server is concerned, the URL the user requested is the one I developed with.

Link to comment
Share on other sites

Ah, okay, that makes sense. Well, actually, no: if I am using mod rewrite to turn the url products/-P1 into products.php5?id=1, say, which is the original URL that I developed with, surely the styles are found relative to that, as they always were? I mean, clearly they aren't, but why? As far as the server is concerned, the URL the user requested is the one I developed with.
CSS is a client-side technology. You are only rewriting the URL on the server-side, but the client is the one that's making the request, and it's requesting a stylesheet relative to the current location ,which is obtained from the URL. Edited by Ingolme
Link to comment
Share on other sites

Pantaloons. Muchos gracias. So, I should just add a leading slash to my links/includes?

Link to comment
Share on other sites

Pantaloons. Muchos gracias. So, I should just add a leading slash to my links/includes?
A leading slash and the full path to the files, relative to the root directory.Not just for your stylesheets, but all the links and images in the page as well.
Link to comment
Share on other sites

Not just for your stylesheets, but all the links and images in the page as well.
Yep, just discovered that...
Link to comment
Share on other sites

*this problem resolved*

Edited by chibineku
Link to comment
Share on other sites

*solved*

Edited by chibineku
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...