Jump to content

Folder Link (/article/123) instead of Normal Link (?p=article&id=123)


jonoc33

Recommended Posts

I didn't really mean it like that. That's really basic stuff.

 

Say I have this link: http://www.site.com/index.php?page=home

I want to make it this: http://www.site.com/home/

 

But it's like a virtual folder, the folder isn't actually on the server.

The most common way of doing it is with mod-rewite which can give you:

doamin.tld/page/myvar

I wrote something up for a client that did not have access to mod-rewrite:

$pages = array('home', 'products', 'services'); //This is actually an SQL query but for the sake of example.
$parts = $_SERVER['REQUEST_URI'];
$parts = preg_replace('%\/index\.php%', '', $parts);
$parts = preg_split('%/%', $parts);
foreach($parts as $part)
{
if(!(is_null($part) || strlen($part) < 1))
 {
	$uriParts[] = $part;
 }
}
if(in_array(strtolower($uriParts[0], $pages)))
{
        $sql = "SELECT title, text FROM content WHERE name='" . mysql_real_escape_string($uriParts['0']) . "' AND published='1'";
        //query....
}

 

With this the links look like domain.tld/?/home or domain.tld/index.php?/home/

Archived

This topic is now archived and is closed to further replies.

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