1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP redirect

Discussion in 'PHP & Perl' started by blackjack, May 7, 2009.

  1. blackjack

    blackjack Regular Member

    Joined:
    Nov 23, 2007
    Messages:
    276
    Likes Received:
    51
    Hi

    Can someone help on the following direct using PHP? I know that it may be easier to use .htaccess but I am noobie with regard to .htaccess so prefer if PHP can be used

    Starting URL www.mydomain.com/weight loss

    Redirect to www.mydomain.com/?key=weight loss


    Thanks in advance
     
  2. zozor

    zozor Junior Member

    Joined:
    Dec 24, 2008
    Messages:
    113
    Likes Received:
    70
  3. crocodile

    crocodile Newbie

    Joined:
    May 23, 2009
    Messages:
    1
    Likes Received:
    0
    you can't do it without using .htaccess
    or maybe you will have to crate a html file name "weight loss"
    and write content inside file:
    <script type="text/javascript">
    location.replace"/?key=weight loss";
    </script>
     
  4. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
    Nope, without htaccess you cannot do the rewrite part to get the keyword in the URL.
    The htaccess you need is only a couple of lines long and you are away :)

    EDIT: Here is the htaccess you will need:
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?key=$1 [L]
    
    And then in your index.php file, have something like:
    Code:
    <php
    $key = $_GET['key'];
    header("Location: http://your.domain.com/index.php?key=$key");
    ?>
    
    Something like that anyways
     
    Last edited: Jul 13, 2009