How to redirect directory to a search string?

Discussion in 'Apache' started by Nite, Aug 3, 2011.

  1. #1
    I use virtual domains, so "domain.com" in the example below is something that will change, e.g., I .htacess file for many domains.

    My old structure is
    http://domain.com/product/this-is-my-search
    Code (markup):
    and I want to redirect that to
    http://domain.com/go.php?q=this is my search
    Code (markup):
    notice the dashes have been removed from the search query.

    How can I do this? THANKS!
     
    Nite, Aug 3, 2011 IP
  2. Nite

    Nite Active Member

    Messages:
    440
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    68
    #2
    I think I found a solution.

    Of importance here are these three lines of code:
    
    RewriteRule ^products/(.*)$ http://%{HTTP_HOST}//go.php?q=$1 [L]
    RewriteRule ^search/(.*)$ http://%{HTTP_HOST}//go.php?q=$1 [L]
    RewriteRule ^product/0/(.*)$ http://%{HTTP_HOST}/go.php?q=$1 [L]
    
    Code (markup):
    Essentially, if the search engines have indexed your site with the construction of URLs as such, this will do a redirect the product name or phrase to go.php as a query. Now, this is experimental (as is most I do in the beginning), and I'd love to hear your feedback!

    Example
    If your domain is indexed as thus in Google:
    
    http://blogmasher.com/products/captain-america-super-soldier-xbox-360
    
    Code (markup):
    You will be redirected to:
    
    http://blogmasher.com/go.php?q=captain-america-super-soldier-xbox-360;&sort=0;&numitem=10;&page=1
    
    Code (markup):
     
    Nite, Aug 3, 2011 IP