This might be a stupid question but it took me days to even figure out what the problem was.
mod_rewrite and passing values separated by forward slashes.
The problem is that the forward slashes are changing the path (I think)
So I'm passing "
admin/login" which gets directed to
admin.php with the
action parameter as
It works fine if i use
%2F to encode the forward slash but then my url looks like
www.mysite/admin%2Flogin which isn't as nice as
It was the css that made me realise what was happening. The login page loaded with no style and a link back to the homepage came up as
www.mysite/admin instead of
Can anyone help me out here. I'm a bit stuck. Is there a way to get apache to stop seeing forward slashes as a path change without encoding them?
Just wanted to add that i've now discovered the first rule in my comment below works fine if i change the forward slash to an equals sign. It stops adding to the website path. Could it be that the behavior i'm describing is actually normal? Confused...
------- Edit 1 ------------ Here's the rules. Anything with a slash causes the behavior I mentioned.
RewriteRule ^(admin)/(login)$ admin.php?action=login [L] RewriteRule ^(admin)$ admin.php?action=all-articles [L] RewriteRule ^(admin)/([a-zA-Z0-9_]+)$ admin.php?action=articlesByTypeTag&topcat=$1 [L]
------- Edit 2 -------------- Ok so after loads more faffing about, and for those who are as confused as i am (if there are any of those) here's the latest.
So the forward slash definitely adds to the Document root as far as the browser is concerned. Here's a basic example. On the login page, which the first rule in the list above handles, i have a link back to the homepage. It was simply href=".", which worked fine before i started using mod_rewrite.
Now the "admin" in "admin/login" is added to the path so that when i hover over the homepage link it displays "localhost/admin/". I changed it to href="/home" and now it works fine.
I added a forward slash to the links for my css files and now they work fine too. I'm assuming that this is because the paths are now relative to the document root in the virtual host rather than relative to what the browser thinks.
Maybe the problem here is that the whole path thing is more complicated than i thought it was. What i wanted was for mod_rewrite to get the values from "admin/login" and apply them to the correct .php with the correct parameter, which is what happens. It's just that the change in how the browser sees things is confusing.
Can anyone tell me if this is how it should be, or is there something really wrong with my setup?