May 262011
 

What is permalink?

permalink definition on a wiki website:

A permalink, or permanent link, is a URL that points to a specific blog or forum entry after it has passed from the front page to the archives. Because a permalink remains unchanged indefinitely, it is less susceptible to link rot. Most modern weblogging and content-syndication software systems support such links. Other types of websites use the term permanent links, but the term permalink is most common within the blogosphere. Permalink is a portmanteau word made from permanent link. Permalinks are often simply stated so as to be human-readable.

How’s the shape of permalink structure?

Generally, dynamic page’s url will look like this:

http://www.example.com/index.php?page=10

become:

http://www.example.com/what-is-permalink,10.html


If we see the appearance of the second link, as if, what-is-permalink,10.html file exist in the server, whereas, in reality there is no such a file. there is no fixed rule in the composition of the permalink, just do not use a space as a link, instead we can use the underscore sign (_) or a minus sign (-) or dots (.) or coma (,), as in the example above, which used a minus sign (-) and coma (,).

How to apply the permalink structure like in the example above?

As we know, nginx support rewrite directive.

if (!-e $request_filename) {
	rewrite ^/(.*),([0-9]+).html$ /index.php?page=$2 last;
	break;
}

In the php code:

<?php
$id = $_REQUEST[page];
// make sure value of $id only contain numeric
if (is_numeric($id))
{
	$query  = "SELECT page_content FROM page_table WHERE page_id`='$id'";
	...
	...
} else {
	echo "404 page";
}
?>

Get value from uri paramater called page, pass it to variable called $id, used for sql query.

Of course, the example I described above is only a very simple example of how permalink made?. compared with the permalink in wordpress or joomla cms that uses a complex system permalink, the example above only very very basic principles of a permalink.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.