Results 1 to 6 of 6

Thread: Custom URL's

  1. #1
    Join Date
    Oct 2005
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Custom URL's

    I'm looking for a way to get all my pages to use index.php in the URL.

    Something like:
    http://www.example.com/index.php
    Should become:
    http://www.example.com/index.php?page=home

    I found this code
    PHP Code:
    <?php
    if ($_GET['page'] == 'home') {
    ?>
    (CONTENT)
    <?php
    }
    ?>
    But the link seems to take me to index.php even if I make up a random name like index.php?page=fjsadblfj or index.php?sdjfgbkjsdbl

    Any help is appreciated.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You would want to place the code you posted above in the index.php page. After which, you would want to edit it for your pages (using if-elseif conditionals).

    Example (index.php):

    Code:
    <?php 
    $default_page = "default.php"; //the default page if the page variable is not set
    
    //start the if-then conditionals
    
     if ($_GET['page'] == "home") {
       include('home.php');
     }
    
     elseif ($_GET['page'] == "testing") {
       include('testing.php');
     }
    
     else {
       include($default_page);
     }
    ?>
    Hope this helps.
    Last edited by thetestingsite; 04-01-2007 at 02:10 AM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Oct 2005
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks, just so I'm clear though, my index.php has nothing except the code you provided right?
    Edit: hmm, can't seem to get this to work
    Code:
    Parse error: parse error, unexpected $end in http://www.example.com/index.php on line 16
    Edit2: I found a code that I got to work.
    PHP Code:
    <?php
                
    if(!isset($_GET['page'])){

       
    $page "home";

    } else {

       
    $page $_GET['page'];

    }
                
    $path $page.".php";

    if (
    file_exists($path)){
          
       include(
    $path);

    } else {
      
       echo 
    "Sorry, the page doesn't exist...";

    }

    ?>
    Thanks for replying anyways, I appreciate the help
    Last edited by tacmig99; 03-31-2007 at 09:29 PM.

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I use a similar system on my site, in fact...
    - Mike

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I'm looking for a way to get all my pages to use index.php in the URL.

    Something like:
    http://www.example.com/index.php
    Should become:
    http://www.example.com/index.php?page=home
    Be aware that this is poor style... once you've done this, use mod_rewrite or something to change the URLs so that /index.php?page=home becomes /home or perhaps /pages/home. Also, avoid the temptation to bung everything into one huge file. Make use of includes.

    I really need to get .htaccess working on my site so I can do this. I think it's a config problem.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I recently found out that you can't edit the htaccess file with my hosting service . But ah, well. I'll live.
    - Mike

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
  •