Jump to content

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


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/

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

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.