PHP redirection when url match

Discussion in 'PHP' started by postcd, Feb 24, 2014.

  1. #1
    Hi,

    i need a php only redirection, when someone open this in webbrowser mydomain.com/?id

    it will redirect to mydomain.com/idiot.php

    please how the php code will look like?
     
    Last edited: Feb 24, 2014
    postcd, Feb 24, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Why don't you do this in .htaccess? Besides, if you wanna do it in PHP, you'd need something to pick up the ?fr-variable - so I would suggest you redo it, perhaps with mydomain.com/french (easier) and still use .htaccess
    In PHP, you could do this by using a check for a $_GET['variable'] and if it's set and matches whatever, you redirect via header('location: URL');
     
    PoPSiCLe, Feb 24, 2014 IP
  3. pozer

    pozer Active Member

    Messages:
    603
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #3
    <?php
    if ( isset( $_GET['fr'] ) ) {
         header( 'Location: http://mydomain.com/french.php' );
    }
    ?>
    PHP:
     
    pozer, Feb 24, 2014 IP
    postcd likes this.
  4. postcd

    postcd Well-Known Member

    Messages:
    1,043
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190