Jump to content

Recommended Posts

Ok, I know that the subject was a bit cryptic, but I am completely confused as to where to look for this information (what to search for in google, etc). Anyway, the point is that I am trying to see if I can replicate the method of breaking a php-enabled site into sections the same way that blogs or wikipedia does, by having "fake" subdirectories:

 

This address: http://www.yourblog.com/balloons/

Is in fact: http://www.yourblog.com/index.php/balloons/  (where I am guessing that the "balloons" part is retained via $_GET or the like)

 

Have I gotten it all wrong and they ARE actually subdirectories (in that case, I'd hate to see what some directory trees look like)? I was convinced otherwise when I have seen websites who's address actually looked like the latter example. Also, the gaming blog Giant Bomb uses this for a subcategory: http://www.giantbomb.com/category/arcade/

And the address: http://www.giantbomb.com/index.php/category/arcade/ points to the same place.

 

Is there any way to replicate this?

 

 

Ps: Please forgive the (potentially) stupid question, it's just that this has bugged me for a while.

One method is to use mod_rewrite which will allow you to create clearn urls like

http://www.giantbomb.com/category/arcade/

 

or you can go the PHP route, example:

<?php

function get_path()
{
    $path_bits = false;

    if(isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] != '/')
    {
        // get the path info
        // path format: index.php/module/page/params1/params2/ etc
        $path = $_SERVER['PATH_INFO'];

        // check that the last character in the path is not a backslash
        // if it is we'll remove it
        if(substr($path, strlen($path)-1, 1) == '/')
        {
            $path = substr($path, 0, strlen($path)-1);
        }

        // explode the bits from the path, eg module, page and parameters
        $path_bits = explode('/', $path);

        // drop index.php
        array_shift($path_bits);
    }

    return $path_bits;
}

$path_bits = get_path();

echo '<pre>' . print_r($path_bits, true) . '</pre>';

?>

i believe the php route is no where near as effective as the mod_rewrite as urls like

http://www.giantbomb.com/category/arcade/

will be interpreted by apache before php can deal with it, (as apache calls the scripts requested), so apache will try to find an index in the arcade folder which is in the category folder in the root directory.

 

i would strongly reccomend mod_rewrite if you are serious about clean/reliable url redirects/formats.

i believe the php route is no where near as effective as the mod_rewrite as urls like

http://www.giantbomb.com/category/arcade/

will be interpreted by apache before php can deal with it, (as apache calls the scripts requested), so apache will try to find an index in the arcade folder which is in the category folder in the root directory.

 

i would strongly reccomend mod_rewrite if you are serious about clean/reliable url redirects/formats.

The only difference is index.php has to be present in the url, it is still as effective as mod_rewrite.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.