mod rewrite redirect 301 help

Discussion in 'Apache' started by dethfire, Apr 16, 2013.

  1. #1
    Trying to redirect this format

    archive/topic/t-59411_Nastase_RHIC_produces_black_holes.html

    to this:

    archive/index.php/t-59411.html


    thanks!!
     
    dethfire, Apr 16, 2013 IP
  2. PopaWoody

    PopaWoody Well-Known Member

    Messages:
    314
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    140
    #2
    RewriteRule ^archive/topic/t-59411_Nastase_RHIC_produces_black_holes.html$ archive/index.php/t-59411.html [L]
    This assumes your have mod_rewrite turned on and an .htacess file in your home or root directory. This will only rewrite an exact match on the URL.
     
    PopaWoody, Apr 16, 2013 IP
  3. dethfire

    dethfire Well-Known Member

    Messages:
    230
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    118
    #3
    Thanks PopaWoody! the t-59411 is a variable id. How would I make that dynamic?
     
    dethfire, Apr 16, 2013 IP
  4. dethfire

    dethfire Well-Known Member

    Messages:
    230
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    118
    #4
    also I want to make sure this is a redirect. the first url does not exist. the content only exists on in the second url.
     
    dethfire, Apr 16, 2013 IP
  5. PopaWoody

    PopaWoody Well-Known Member

    Messages:
    314
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    140
    #5
    Your first question is a bit more involved and would require a different set of rules and regexes . The second part...the redirect. What I gave you will redirect any request...whether it actually exists or not to the redirect URL. Itwould be consider at 301 redirect. You could make it a 302...but I think that is not what is needed.
     
    PopaWoody, Apr 16, 2013 IP
  6. dethfire

    dethfire Well-Known Member

    Messages:
    230
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    118
    #6
    I got what I wanted mostly from this:

    RewriteRule ^archive/topic/t-([0-9-]+)([[a-zA-Z0-9_]*).html$ archive/index.php/t-$1.html [R=301,L]
    RewriteRule ^archive/topic/t-([0-9-]+)$ archive/index.php/t-$1.html [R=301,L]

    RewriteRule ^archive/topic/([0-9-]+).html$ archive/index.php/t-$1.html [R=301,L]

    RewriteRule ^archive/t-([0-9-]+)([[a-zA-Z0-9_]+).html$ archive/index.php/t-$1.html [R=301,L]
    RewriteRule ^archive/t-([0-9]+)$ archive/index.php/t-$1.html [R=301,L]


    I assume it's not very efficent. Is there a more compact way to do this?
     
    dethfire, Apr 16, 2013 IP