homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

301 old to URL to new one with spaces %20

 12:38 pm on Sep 11, 2007 (gmt 0)

I've got to redirect an old URL to a new one with spaces in it.

Have been using the following successfully where there are no spaces, but it crashes when spaces are included in the new destination name...

RewriteCond %{query_STRING} ^q=12345$
RewriteRule ^path/file\.php$ /path2/Place Name/Other Name? [R=301,L]

equally the following doesnt work either:

RewriteCond %{query_STRING} ^q=12345$
RewriteRule ^path/file\.php$ /path2/Place%20Name/Other%20Name? [R=301,L]

Help much appreciated!

[edited by: Adam_C at 12:41 pm (utc) on Sep. 11, 2007]



 12:40 pm on Sep 11, 2007 (gmt 0)

ok, nailed it

RewriteCond %{query_STRING} ^q=12345$
RewriteRule ^path/file\.php$ "/path2/Place Name/Other Name?" [R=301,L]


 12:56 pm on Sep 11, 2007 (gmt 0)

Wow, that's new! I've never seen a quoted substitution URL before, and it's great to know that it works.

The usual solution is to use %20 for the space and use the [NE] flag on the rule, or to escape the space with a preceding backslash ( e.g. "\ " ). But quoting the string is easier and looks much more readable.

Thanks for posting your solution!



 7:40 pm on Sep 11, 2007 (gmt 0)

Using spaces in URLs is so problematical. They are often encoded as %20 and make URLs unreadable. Additionally, sometimes they become double encoded (where the % sign itself is encoded again) and that can cause all sorts of problems.

Can I suggest that you use hyphens or dots between words? Is there a good reason why spaces have been used? If the URL hasn't yet been indexed, I would strongly suggest that it be changed, to lose the spaces.

If it is a script that generates the pages from a database, then it is fairly easy to take the text that I assume you currently use for both the title and for the URL and add hyphens or dots between the words for whatever you are going to use for the URLs and for the links to those pages.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved