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.
mod_rewrite file path problems
Moderator: General Moderators
Re: mod_rewrite file path problems
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:
Use:
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>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.
Re: mod_rewrite file path problems
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.
Edit:
My mistake, I forgot my stylesheet wasn't in the root directory.
Code: Select all
<link href="/styles.css" rel="stylesheet" type="text/css" />My mistake, I forgot my stylesheet wasn't in the root directory.