tricky htaccess 301 redirect

Discussion in 'Site & Server Administration' started by TechMaster, Jan 19, 2012.

  1. #1
    hello there,

    I need to set 301 redirect for selected urls only.

    my old htaccess code is....

    RewriteRule buy.php$ product.php?&%{QUERY_STRING}
    RewriteRule buy.php$ product_details.php?&%{QUERY_STRING}
    Code (markup):
    obviously for one url it was giving 404-soft error becuase of two buy.php

    so i changed one url as below.....

    RewriteRule [B]buy-now.php[/B]$ product.php?&%{QUERY_STRING}
    RewriteRule buy.php$ product_details.php?&%{QUERY_STRING}
    Code (markup):
    Now, google has already indexed old url.

    How do i set 301 redirect for old url to new buy-now.php???
     
    TechMaster, Jan 19, 2012 IP
  2. blacknet

    blacknet Active Member

    Messages:
    709
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    70
    #2
    
    RewriteRule buy-now.php$ product.php?&%{QUERY_STRING} [R=301,L]
    RewriteRule buy.php$ product_details.php?&%{QUERY_STRING} [R=301,L]
    
    Code (markup):
     
    blacknet, Jan 19, 2012 IP
  3. TechMaster

    TechMaster Peon

    Messages:
    225
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    no it did not work.

     
    TechMaster, Jan 19, 2012 IP
  4. skseofleet

    skseofleet Peon

    Messages:
    102
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I am not a programmer but i use the following code for 301

    options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host}^buy-now.php[nc]
    rewriterule ^(.*)$ buy.php 1[r=301,nc]

    try it........
     
    skseofleet, Jan 22, 2012 IP