Redirect to new domain, replace + with -

Discussion in 'Apache' started by Kerosene, Oct 23, 2011.

  1. #1
    I need to redirect an old domain to a new domain, and while I'm at it, I'd like to move from using + as the spacer, to using - instead.
    I know it's pretty simple, but I'm banging my head against the wall here.

     
    Kerosene, Oct 23, 2011 IP
  2. Sorror

    Sorror Active Member

    Messages:
    376
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #2
    It's doable with regex, but are you sure that the old domain doesn't have urls with '+' that aren't spacers?
     
    Sorror, Oct 27, 2011 IP
  3. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #3
    Absolutely positive. All OLD urls are old.olddomain.com/searchterm or old.olddomain.com/search+term, no spaces.
    I've already done the redirect with a PHP 301, but if anyone can give me an htaccess solution it would be good.
     
    Kerosene, Oct 27, 2011 IP
  4. Sorror

    Sorror Active Member

    Messages:
    376
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #4
    I think it's way better to deal with this on a php level. All I got with regex is a series of 301 redirects for every character changed (3 redirects if there are 3 +'s within url, and so on). There is perhaps some more elegant way to deal with it, but it is even more elegant with simple php code str_replace('+', '-', $_SERVER['QUERY_STRING']). This way you also don't need to worry about infinite 301 loops.
     
    Sorror, Oct 27, 2011 IP
  5. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #5
    Yeah that's what I ended up doing a few days ago. I've got a massive learning difficulty with htacess + regex. If I can do it with PHP instead, I usually do :)
     
    Kerosene, Oct 27, 2011 IP