Pretty URLs Using Multiviews

I saw a post on about how it’s nice to have “pretty urls” that are easy to tell people. While i’m not sure anyone would remember slash some ridiculous post name, it’s nice to have for search engines. Unfortunately, it didn’t really go into detail about how to accomplish the urls. A lot of people suggested mod_rewrite. Yes, it’s something you can use, but kind of a pain to set up.

A good alternative to mod_rewrite is to use Multiviews. Multiviews are specified in a per-directory basis, and have to be set explicitly. `

<Directory /path/to/your/stuff>
Options  Multiviews

You can then use this function to make it useful:

function assign_get_vars()
	$args = func_get_args();
	$path_info = $_SERVER['PATH_INFO'];
	$p = explode("/", substr($path_info,1) );

	// assign the vars
	$total = count($args);
	for($i=0; $i < $total; $i++)
		$name = $args[$i];
		$_GET[$name] = $p[$i];
		$_REQUEST[$name] = $p[$i];

` Example: Say you have this page: /forums/view.php You can call it like this: /forums/view/444/2

In your PHP script, add this to the top: `



You can now refer to $_GET[’thread’] and $_GET[‘page’] as if they were set by the server.

A benefit of Multiviews is that it lets you drop the file extension.

Hope this is of some use to someone. Comments are welcome and encouraged.

If you found this post helpful, please consider sharing to your network. I'm also available to help you be successful with your distributed systems! Please reach out if you're interested in working with me, and I'll be happy to schedule a free one-hour consultation.