PDA

View Full Version : Mod rewrite and encoded URLs?



duncanhall
June 17th, 2007, 07:52 AM
I have a rewrite rule set up to give pages such as "students/johnny_surname" rather than "/students.php?id=45".

This is how it stands at the moment.



RewriteEngine on
RewriteBase /dev/
RewriteRule ^students/([A-Za-z\_\'\-]+)/?$ students.php?student=$1 [QSA]
students.php takes the names supplied and gets the relevant details.

This all works fine, except for surnames with spaces in them.

If I navigate to

/students.php?student=min-kyung_kate%20nam

or

/students.php?student=min-kyung_kate nam

Then everything works fine. The names are put through urldecode() and it works as expected.

But if I go to

students/min-kyung_kate%20nam

or

students/min-kyung_kate nam

Then the rewrite seems to fall over. I just get a 404.

Can anyone help?

simplistik
June 17th, 2007, 09:55 AM
yea well with the web you should never have spaces in your urls. so to fix it... don't use spaces...

duncanhall
June 17th, 2007, 10:10 AM
Fair point. I guess I'll have a look at replacing spaces with "_".

Hopefully noones parents were funny enough to include an underscore in there name.

simplistik
June 17th, 2007, 10:24 AM
Well it shouldn't be up to the parents, you should be able to allow them to make it look however they want but on the process page you convert it. you need to convert the urls into friendly urls so if the name is 'John Doe Wins' you need to be able to take 'John Doe Wins' convert it for your url to say, 'john_doe_wins' or 'john-doe-wins'

duncanhall
June 17th, 2007, 10:48 AM
Ha, no I meant hopefully noone actually called their child something like "Jennifer Ridiculous_Name Smith".

It should be fairly straight forward, I'm already inserting an underscore between the first and last name, so I'll give it a go and see what happens. Cheers.

duncanhall
June 17th, 2007, 11:09 AM
Sweet, working now. Good call, cheers.

simplistik
June 17th, 2007, 11:47 AM
Ha, no I meant hopefully noone actually called their child something like "Jennifer Ridiculous_Name Smith".

:lol: that'd be pretty funny though

Glad you got it workin :thumb2: