Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Other Scripting (https://www.askmehelpdesk.com/forumdisplay.php?f=455)
-   -   How do I redirect an existing website with htaccess without redirecting major robots? (https://www.askmehelpdesk.com/showthread.php?t=646971)

  • Mar 29, 2012, 04:02 PM
    zylstra
    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]

  • Mar 30, 2012, 09:58 AM
    rpray2007
    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 ;-)
  • Mar 30, 2012, 04:52 PM
    zylstra
    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]


  • All times are GMT -7. The time now is 04:27 AM.