Page 1 of 1

mod_rewrite file path problems

Posted: Tue May 27, 2008 8:05 am
by davidtube
Hi. I've only just today managed to get mod_rewrite working. I'm very happy, it's taken me ages to start getting my head round it at all.

So now my urls have changed from
example.com?colour=red
to
example.com/red

but the page now acts like it is inside a deeper directory, so links need to point back one level. Is there a way to fix this with mod_rewrite or do I need to just change all my links? I can't really change my links because all the pages include same navigation.php file.

Re: mod_rewrite file path problems

Posted: Tue May 27, 2008 9:58 am
by pickle
You need to update your links. example.com/red is a subdirectory of example.com. Whether it's virtual or not doesn't matter - some $_SERVER variables are updated to reflect the new "virtual" path to the file on the server.

If you update all your links to be absolute (but relative to the host) you will be able to use the same file in multiple directories & depths.

Rather than:

Code: Select all

<a href = "myfile.php">test</a>
Use:

Code: Select all

<a href = "/myfile.php">test</a>

Re: mod_rewrite file path problems

Posted: Tue May 27, 2008 10:06 am
by davidtube
Oh thanks. I never realised I could make links absolute but relative to the host. Although it doesn't seem to be working with the link to my style sheet.

Code: Select all

<link href="/styles.css" rel="stylesheet" type="text/css" />
Edit:
My mistake, I forgot my stylesheet wasn't in the root directory.