1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

URL redirection via PHP

Discussion in 'PHP' started by cyclotron, Sep 16, 2010.

  1. #1
    Hey guys,

    I have a site for example http://www.sitename.com/mylayouts.php

    But have htaccess'ed it so it is http://www.sitename.com/mylayouts/page/1


    Now, to authorize the user via a 3rd party API, they do not accept the htaccess version of the URL, it needs to be done via the original.

    Upon authorization, which I have the code for already, I need some sort of code that will see if it is viewing

    the mylayouts.php version of the URL and if so, redirect it too mylayouts/page/1

    If that is possible. Thanks :)
     
    cyclotron, Sep 16, 2010 IP
  2. Leron

    Leron Active Member

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    53
    #2
    I hope i understood what it is you are saying. but try something like this nothing fancy. place that into your mylayouts.php file after all needed code had finished loaded:
    if(basename(__FILE__)=='mylayouts.php') header('location:mylayouts/page/1');
    PHP:
     
    Leron, Sep 16, 2010 IP
  3. cyclotron

    cyclotron Active Member

    Messages:
    213
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    73
    #3
    Thanks mate, worked a treat!
     
    cyclotron, Sep 16, 2010 IP
  4. Slick

    Slick Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just for reference you can also redirect after a period of time using php
    header("refresh:5;url=mylayouts/page/1");
    PHP:
    This example being 5 seconds..

    The only problem with header redirects is that they must be called before any other output... you can get around this with php buffering by calling a function at the beginning of your page and at the end
    ob_start();
    
    // website code here
    
    ob_end_flush();
    PHP:
     
    Slick, Sep 16, 2010 IP