Ask Experts Questions for FREE Help !
Ask
    zylstra's Avatar
    zylstra Posts: 83, Reputation: 11
    Junior Member
     
    #1

    Mar 29, 2012, 04:02 PM
    How do I redirect an existing website with htaccess without redirecting major robots?
    To temporarily test sales on a newly redesigned site (that resides on sub.domain.com) without disrupting my existing search engine rankings I would like to redirect all visitors that aren't a major crawler to the new subdomain. The existing site contains the product ID (SKU) at the end of the product page URLs after an underline character, "_". I would like to redirect visitors that enter on a product page to the newly redesigned product page with the structure, http://sub.domain.com/toy/sku-[Product ID]?a=test . All others (including visitors that enter on category pages) I would like to redirect to the home page. Is this a good .htaccess file for this task?


    Code:
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_USER_AGENT} !^(AltaVista|Googlebot|msnbot|Slurp)
    RewriteRule ^_(.*)$ http://sub.domain.com/toy/sku-$1?a=test [R=302,L]
    
    RewriteCond %{HTTP_USER_AGENT} !^(AltaVista|Googlebot|msnbot|Slurp)
    RewriteRule (.*) http://sub.domain.com/ [R=302,L]
    rpray2007's Avatar
    rpray2007 Posts: 319, Reputation: 23
    Full Member
     
    #2

    Mar 30, 2012, 09:58 AM
    I think it should work based on my understanding of regex and htaccess rules. My only question is if you have the list of the bots correct - maybe look at your access logs to make sure you got the correct user-agent names. They look right to me...

    The order of these rules is important too - the catch-all rule has to come after the restrictive one. And you are doing this by providing the 'L' directive in the redirect which tells to stop redirecting if this rule fires.

    You can look at this link to get more details.
    mod_rewrite - Apache HTTP Server

    But you've probably read it ;-)
    zylstra's Avatar
    zylstra Posts: 83, Reputation: 11
    Junior Member
     
    #3

    Mar 30, 2012, 04:52 PM
    I had a couple mistakes. The fixed code is:

    Code:
    RewriteCond %{HTTP_USER_AGENT} !(AltaVista|Googlebot|msnbot|Slurp)
    RewriteRule _(.*)$ http://sub.domain.com/toy/sku-$1 [R=302,L]
     
    RewriteCond %{HTTP_USER_AGENT} !(AltaVista|Googlebot|msnbot|Slurp)
    RewriteRule (.*) http://sub.domain.com/ [R=302,L]

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

What are ways that I can make money with my existing website? [ 2 Answers ]

My shop website is up and running. Now how do I get companies to want to advertise on it and how can I make additional cash with it?

Can I capitalize a new form page to an existing website? [ 1 Answers ]

My IT team is requesting that 'new forms' that need creating and deploy to an existing website be capitalized. In the world of accounting is that really a capital project or just ongoing maintanence of an existing site

I do not no what is the error in this .htaccess [ 3 Answers ]

Hi there this is my first post here I have a new website I have played with my htaccess file but I have no backup for it and now it produce internal server Error I do not know what to do this the code of it please any help will be appreciated #php_flag error_reporting 1 php_flag...

Redirecting history [ 2 Answers ]

Is there a way to redirect deleted history so you can retrieve it later


View more questions Search