Odd behaviour with a rewrite rule

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Odd behaviour with a rewrite rule

Post by rsmarsha »

I have the following rewrite rule:

Code: Select all

RewriteRule ^index/([a-z0-9]+) index.php?page=$1
To turn

url/index.php?page=name

into

url/index/name

It works fine on http://www.irealms.co.uk yet on the host i'm working on, it doesn't.

Instead of showing (url/index/name) in the address bar, it changes to (url/index.php?page=name) on loading the page. So it's showing the url the rule is meant to be disguising.

The host told me this :
Your rewrite rule will always rewrite the URL to the extended form as it is. You may want to think about using a rewite condition if you want some exceptions.
Now if that is the case, why does it now behave like this on my own server? Also how do i stop it doing this?

Another problem is the rule doesn't work at all on the work server, using IE, and does the strange redirect i mentioned above when using firefox.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Your arguments are backwards - you need to put the format you're expecting first, and the format you want second:

Code: Select all

RewriteRule ^index.php?page=([a-z0-9]+) index/$1
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Well the rule works fine on my other server, so if it's backwards why would it work there?

Also all the info i found on the web like :

http://www.ilovejackdaniels.com/mod_rew ... _sheet.pdf

and

http://www.sitepoint.com/article/guide-url-rewriting/2

All say to do it the way i'm doing it atm?

If these are wrong then please explain, as i'm just working from the web guides i found.

If what you say is correct then what is the point of the rewrite rule? It would take an already long url and shorten it. What i want it to do is take a short URL and know where that url links to on the server with all the variables. As it does on http://www.irealms.co.uk.


Obviously the main problem is i know the rule works on one server, but on the other index/home changes to index.php?page=home in the bar, even though it should stay as index/home and display the page as if i'd entered index.php?page=home.
Post Reply