Results 1 to 3 of 3

Thread: Help with mod rewrite problem

  1. #1
    Join Date
    Feb 2004

    Help with mod rewrite problem


    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,

  2. #2
    Join Date
    Dec 2005
    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> 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

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

    HTML Code:
    <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.
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...

  3. #3
    Join Date
    Feb 2004
    Thanks, that does seem like a good solution - will look into this.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center