SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    rewrite (not redirect) with php?

    i know there's this which redirects:
    Code:
    <?php
    header("Location: http://www.example.com/"); /* Redirect browser */
    
    /* Make sure that code below does not get executed when we redirect. */
    exit;
    ?>
    but is there a way to rewrite? that is leave the user's url as it is in the browser's address bar, but behind the scenes, serve another particular file/page?

    i also know this is possible with apache .htaccess files etc. but i'm wondering if it's possible with php?

    thanks.


    edit:

    i suppose simply doing it with if and includes would amount to what i'm asking e.g. in the main file:

    if( suchAndSuch) include('one.php');
    else include('two.php');

    that's probably how i should do it but i'd still be intersted if there is a rewrite thing in php.

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope. No rewrite. Look into Apache's mod_rewrite or Ajax or includes (as at the bottom of your post).
    I will not flame the newbies,
    I will not flame the newbies,
    I will flame the newbies...
    Table free is the way to be!

  3. #3
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    There is one way but it is a complete PITA....

    If you had your URL:

    www.mysite.com/mypage
    which physically doesnt exist on the server you get sent to your 404 page.
    On your 404 page you could set up a script to read the refering url and server the right page.

    It's not pretty, it's not practical and it certainly isn't logical but it is a way....

    Personally - mod_rewrite
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #4
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    i want to use information from a database which isn't going to be available in .htaccess. so i'll need to use the if include method. not a problem; that does kind of amount to what i'm asking really i suppose. thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •