// you’re reading...

PHP

mod_url without mod_url?

I know the title seems to make no sense but bear with me a minute. mod_url is an extension for the apache server that allows you to specify automatic routes for urls. So someone going to http://wheremy.feethavebeen.com/xangelo would see their profile page instead of going to http://wheremy.feethavebeen.com/profile?=xangelo It’s just a pretty way of formatting URLs. As an experiment, I decided to construct a handy little function that will allow you to parse links like http://wheremy.feethavebeen.com/index.php/profile/xangelo/view to create a more readable url structure.

<?php
function parse(){
		$self = $_SERVER['PHP_SELF']; 
		$e = explode('index.php',$self);
                $t = array();
		$t['base'] = $e[0]; 
		$x = explode('/',$e[1]); 
 
		foreach($x as $key=>$val){
			if($val == '')
				unset($x[$key]); 
		}
		$t = array_values($x); 
                return $t;
	}
?>

To create a link to the same page the array key ‘base’ can be used followed by a / and then the options you want. To create a link to my profile you could do this:

<?php
$url = parse(); 
echo '<a href="'.$url['base'].'/profile/xangelo/view">My Profile</a>';
?>

Discussion

No comments for “mod_url without mod_url?”

Post a comment