Forum Moderators: phranque

Message Too Old, No Replies

Rewriting hyphen to plus sign

         

Mystique

7:42 pm on Aug 2, 2009 (gmt 0)

10+ Year Member



Guys, how to change the (-) to (+) using rewrite rule?

i want to redirect my old site to the new site & change the separator sign also for example:

oldsite.com/search/key-word

to

newsite.com/key+word

currently i'm put htaccess file on the oldsite.com/search


redirect 301 /search/ http://newsite.com/

but how to change the (-) sign to (+)

Thanks

g1smd

10:24 pm on Aug 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need to use RedirectMatch or RewriteRule (and I would use the latter of those).

You'll use patten matching to match the input URL, and the target URL will contain the values previous stored in those backreferences, along with the [R=301] flag.

You'll therefore be using a redirect, not a rewrite.

jdMorgan

11:51 pm on Aug 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And note that the actual URL will be "newsite.com/search/key%2Bword" if you do this, because a plus sign is a reserved character and cannot appear in a URL-path unless it is encoded. It *can* be used without being encoded in a query string appended to a URL-path, but not in the path itself.

For this reason, hyphens, underscores, or other unreserved characters would be a better choice.

See RFC2396 - Uniform Resource Identifiers (URI): Generic Syntax [faqs.org].

Jim