Jump to content
MakeWebGames

Recommended Posts

Posted (edited)

And for those working withouth htaccess

 

<?php
// Example 'dirty' url: http://www.site.com/index.php?page=page&subpage=subpage&id=id
// Example 'clean' url: http://www.site.com/index.php/page/subpage/id/

$page = "index.php";

if ( $url = stristr($_SERVER['REQUEST_URI'], 'index.php') ) {
   // $url == 'index.php/page/subpageid
   if( $url[strlen($url)-1] == '/') {
       // Check if the URL ends with a '/'
       $url[strlen($url)-1] = '';
   }
   $url_segments = explode('/', $url);
   // $url_segments[0] == 'index.php';
   if( isset($url_segments[1]) && $url_segments[1] != '' ) {
       // If the page in the url is entered, gets $_GET['page'] the value
       $_GET['page'] = $url_segments[1];
       if( isset($url_segments[2]) && $url_segments[2] != ''){
           //If the subpage in the url is entered, gets $_GET['subpage'] the value
           $_GET['subpage'] = $url_segments[2];
           if( isset($url_segments[3]) && $url_segments[3] != '') {
               //if the subpage in the url is entered gets $_GET['subpage'] the value
               $_GET['subpage'] = $url_segments[3];
           }
       }
   }
} else {
   $_GET['page'] = $page;
}
?>
Edited by rjddev
typo
Posted
And for those working withouth htaccess

 

<?php
// Example 'dirty' url: http://www.site.com/index.php?page=page&subpage=subpage&id=id
// Example 'clean' url: http://www.site.com/index.php/page/subpage/id/

$page = "index.php";

if ( $url = stristr($_SERVER['REQUEST_URI'], 'index.php') ) {
   // $url == 'index.php/page/subpageid
   if( $url[strlen($url)-1] == '/') {
       // Check if the URL ends with a '/'
       $url[strlen($url)-1] = '';
   }
   $url_segments = explode('/', $url);
   // $url_segments[0] == 'index.php';
   if( isset($url_segments[1]) && $url_segments[1] != '' ) {
       // If the page in the url is entered, gets $_GET['page'] the value
       $_GET['page'] = $url_segments[1];
       if( isset($url_segments[2]) && $url_segments[2] != ''){
           //If the subpage in the url is entered, gets $_GET['subpage'] the value
           $_GET['subpage'] = $url_segments[2];
           if( isset($url_segments[3]) && $url_segments[3] != '') {
               //if the subpage in the url is entered gets $_GET['subpage'] the value
               $_GET['subpage'] = $url_segments[3];
           }
       }
   }
} else {
   $_GET['page'] = $page;
}
?>

Thanks for this, I'm sure it will be very helpful mate. :)

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.   Paste as plain text instead

  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...