treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Grab end or url (like domain.com/info) and use a var 4 index

  • Hi,

    I wanted to know if anyone new a way of grabbing the end of the url. What I would like is the normal "domain.com/index.php" then when you use a different url like "domain.com/info" the info will become a variable for the index page.

    Does anyone know how to do this or a tutorial that will help with this type of thing?
  • put this in a .htaccess file:


    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php?url=$1 [L]


    and put this in the index.php:


    //url rewrite
    $url = strip_tags($_GET['url']);
    $url = explode('/', $url);

    echo '<pre>';
    print_r($url);
    echo '</pre>';


    now all the stuff after the domainname is in the $url variable.
  • Thanks so much! I will defiantly give this a try!