Click to See Complete Forum and Search --> : Help with mod rewrite problem


Black_Knight
04-07-2009, 07:04 AM
Hi,

Was wondering if anyone could shed any light on a strange problem I'm having with mod_rewrite:
I'm trying to rewrite urls so that www.domain.com/mycategory
displays the page www.domain.com/page.php?catid=1.

My rewrite rule is

RewriteRule ^mycategory/?$ page.php?catid=1


This works fine, until I go to www.domain.com/mycategory/
Note the final /.

The rewrite rule works BUT all my CSS & JavaScript includes fail, apparently because they are relative references of the form href="./css/styles.css" etc and now the active directory appears to be one level deeper because of the trailing /.

I know there must be a simple way to solve this without having to use absolute references for CSS (which I don't want to do because I want to be able to use the exact same pages for my offline testing).

Any ideas appreciated,
Thanks

aj_nsc
04-07-2009, 09:23 AM
I've been there, and spent a long time trying to figure out what to do to fix that problem too. I came to the conclusion to use the <base> (http://www.w3schools.com/TAGS/tag_base.asp) tag in your HTML document head tag.

EDIT: As for your offline testing, I usually use a conditional php statement based on $_SERVER['SERVER_NAME'] whether to include


<base href="http://localhost/" />


or


<base href="http://www.myserver.com/" />


and that way, I never have to change anything in my code when I upload my pages to my server, because the PH conditional just picks out which base tag to use.

Black_Knight
04-08-2009, 04:59 AM
Thanks, that does seem like a good solution - will look into this.