How to Redirect dynamic URL to static one!

Discussion in 'Apache' started by fundl, Jul 1, 2009.

  1. #1
    I want to redirect a dynamic url which looks like,
    www.example.com/?subaction=showfull&year=2009&month=03&day=06&news_name=example-post
    Code (markup):
    to the static one i.e.
    www.example.com/2009/03/06/example-post.html
    Code (markup):
    how can i do that plz specify a .htaccess code for that
     
    fundl, Jul 1, 2009 IP
  2. fundl

    fundl Member

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    plz mention htaccess code for that or any other through which i can redirect it.
     
    fundl, Jul 1, 2009 IP
  3. Wrighty

    Wrighty Peon

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    RewriteEngine On
    RewriteRule ^?subaction=showfull&year=([0-9]+)&month=([0-9]+)&day=([0-9]+)&news_name=([a-z0-9_-]+)$ /$1/$2/$3/$4.html
    Code (markup):
    :)
     
    Wrighty, Jul 2, 2009 IP
  4. fundl

    fundl Member

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    its not working i just checked and got "500 Internal server error"
     
    fundl, Jul 2, 2009 IP
  5. Wrighty

    Wrighty Peon

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    RewriteEngine On
    RewriteRule ^\/([0-9]+)\/([0-9]+)\/([0-9]+)\/([a-z0-9_-]+)\.html$ ?subaction=showfull&year=$1&month=$2&day=$3&news_name=$4)
    Code (markup):
    :)
     
    Wrighty, Jul 2, 2009 IP
  6. fundl

    fundl Member

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    ok i just make you clear the following code
    is already in my .htaccess but anyhow google has indexed the dynamic URL and that could penalize me because static and dynamic both are giving the same content.so i want to redirect the dynamic one to static URL which is already configured to convert in dynamic but in serverside.
     
    fundl, Jul 2, 2009 IP
  7. fundl

    fundl Member

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    the second code you mentioned will convert static to dynamic i think is'nt it?
     
    fundl, Jul 2, 2009 IP
  8. zain654321

    zain654321 Peon

    Messages:
    202
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You will need a RewriteRule with [R=301,L] flags for this, not a redirect. redirect cannot see Query Strings.
    You'll need a RewriteCond to test the QUERY_STRING too. Do not mix RewriteRule and redirect here. Use RewriteRule for all of the rules.

    As this is one of the most requested topics here (almost every day it seems), there are a very large number of prior examples to browse.
     
    zain654321, Jul 8, 2009 IP