Remove The %20 In URL

Discuss practical ways rearrange URLs using mod_rewrite.

Remove The %20 In URL

Postby designguru » Wed Nov 29, 2006 9:26 pm

I would like to take the following URL structure and turn it into the following....any help on this matter is greatly appreciated at this time. I have got the url close to what I am looking for, but I can't seem to get the %20 out. I know that it can be fixed on the application side and by using php. However these aren't options for this client because they have several sites running already and they have their sites in html as well.

Original URL:

Code: Select all
ResultsGeneral.html?stype=0&kwds=boston%20red%20sox


Desired URL:

Code: Select all
boston-red-sox.html


I am not for sure if this is even possible or not...I can get it close but it just wants to always leave in the %20 part and I can't seem to get it exactly like I want it. This is the URL that I get.

Code: Select all
boston%20red%20sox.html


This is the mod rewrite code I am using.

Code: Select all
RewriteEngine On
RewriteRule ^([^-]*)\.html$ /ResultsGeneral.html?stype=0&kwds=$1 [L]


Thank you to anyone that can help me!
designguru
 
Posts: 2
Joined: Wed Nov 29, 2006 9:20 pm

Postby richardk » Thu Nov 30, 2006 9:55 am

That's not something for mod_rewrite to do. You have to change the links in the pages, so you can edit the scripts to replace the dashes with spaces before the variable is used (or rename real files).

If you need old links (on other sites) to redirect to the new URLs that can be done.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

What is this guy talking about then from another forum?

Postby designguru » Thu Nov 30, 2006 10:32 am

Don't guess I understand what this guy is doing here...

Here is a mod rerwrite tip that I found by experimentation, it deals with pain in the *** spaces (or %20) in the query string

RewriteRule ^foo-bar.htm$ index.php?cat=foo\ bar [nocase]

notice the "\ " is a way of expressing spaces in mod rewrite....to take it 1 step further:

RewriteRule ^foo\sbar.htm$ index.php?cat=foo\ bar [nocase]

notice the \s is a way of matching spaces

Hope this helps someone - BTW this was a project i took over - would never consider putting spaces into the URL if possible AVOID!
designguru
 
Posts: 2
Joined: Wed Nov 29, 2006 9:20 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Majestic-12 [Bot] and 7 guests

cron