mod_rewrite file path problems

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

mod_rewrite file path problems

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: mod_rewrite file path problems

Post 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>
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

Re: mod_rewrite file path problems

Post 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.
Post Reply