Redirect 301 dynamic urls

Discussion in 'Site & Server Administration' started by Cheaperholidays, Feb 23, 2006.

  1. #1
    Hello Everyone

    I have a problem i am trying to redirect 301

    resort-details.php?id=6 to /travel-weather6.htm

    So that the dynamic url will always direct to the new static pages

    Many Thanks
    Dave
     
    Cheaperholidays, Feb 23, 2006 IP
  2. chengfu

    chengfu Well-Known Member

    Messages:
    113
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Why don't you just insert the redirect into the php file like this:
    
    header('HTTP/1.1 301 Redirect permanent');
    header('Location: http://www.yoursite.com/travel-weather'.$_GET['id']);
    exit;
    
    Code (markup):
    It should also be possible via mod_rewrite but might be a little more complicated.

    Edit: Forgot the HTTP status code
     
    chengfu, Feb 23, 2006 IP
  3. chengfu

    chengfu Well-Known Member

    Messages:
    113
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #3
    To do the redirect using mod_rewrite add something like the following to your .htaccess:
    
    RewriteEngine On
    RewriteCond %{REQUEST_URI}      resort-details\.php
    RewriteCond %{QUERY_STRING}     id=([0-9]+)
    RewriteRule ^.*$        http://www.site.com/travel-weather%1.html? [R=301,L]
    
    Code (markup):
     
    chengfu, Feb 23, 2006 IP
  4. Cheaperholidays

    Cheaperholidays Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi Chengfu

    The urls are dynamic so cannot use the header code but thanks anyway, itl looks like it might be some form of Mod-rewrite
    <edit> Chengfu you are a star works a treat....kiss kiss
    Many Thanks
     
    Cheaperholidays, Feb 23, 2006 IP
  5. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The 301 redirect already posted should work fine with any dynamic urls.
     
    mad4, Feb 23, 2006 IP