1

I am working on a new script that basically instead when somebody searches for something on my website how it normally goes to here:

http://domain.com/index.php?q=apples

to

http://apples.domain.com

I have made this work perfectly in PHP as well as htaccess but the problem I am having is using the original keyword afterwards on the new subdomain page.

Right now I can use parse_url to get the keyword out of the url but my script also filters out potential problems like:

public function sanitise($v, $separator = '-')
    {
        return trim(
            preg_replace('#[^\w\-]+#', $separator, $v),
            $separator
        );
    }

So if somebody searches for netbook v1.2

The new subdomain would be:

http://netbook-v1-2.domain.com

Now I can take the keyword out but it's with the dashes and not original. I am looking for a way to send over the original keyword with the 301 redirect as well.

Thanks!

2 Answers2

1

You can either just replace the hyphen with spaces when they visit the new subdomain or, since you're on the same top-level domain, you can just cookie the keyword when redirecting them:

setcookie('clientkeyword', 'netbook-v1-2.domain.com:netbook v1.2', 0, '/', '.domain.com');
webbiedave
  • 48,414
  • 8
  • 88
  • 101
  • Works great when people are searching for the item themselves, but if a user clicks on apples.domain.com from google or something, nothing would show. :( – deadlyeffect Feb 21 '12 at 22:04
  • That's why I also stated `just replace the hyphen with spaces` from `$_SERVER['HTTP_HOST']`. There's nothing else you can do in that case. – webbiedave Feb 21 '12 at 22:08
  • After thinking about it, you are absolutely right. There is nothing else I can do about it so this should be good enough. Thank you! – deadlyeffect Feb 21 '12 at 22:11
0

Look at this answer: https://stackoverflow.com/a/358334/992437

And see if you can use the POST or GET data that's already there. If so, that might be your best bet.

Community
  • 1
  • 1
Tango Bravo
  • 3,221
  • 3
  • 22
  • 44
  • That specific flag in the .htaccess tells the POST data and GET data to be redirected as well. Am I missing something? – Tango Bravo Feb 21 '12 at 21:45
  • You're confusing rewrite with redirect. The client will not repost its data. – webbiedave Feb 21 '12 at 21:47
  • I must be completely confused. But from my experience, RewriteRule's can redirect as well ([L,R=301]). That's part of what they do. I'll look into this more though, as I might have missed something. – Tango Bravo Feb 21 '12 at 22:03