How WordPress permalink system works? How WordPress permalink system works? wordpress wordpress

How WordPress permalink system works?


The commonly available apache module mod_rewrite can help you out with this. What you do is write rewrite rules inside an .htaccess file, and through the rewrite, fancy structures that would have normally resembled a file system get sent to a PHP file as $_GET parameters.

For example, if you wanted to replace something like: ?reactor=13 into /reactor/13/

Write this rewrite rule in the .htaccess file:

RewriteEngine onRewriteRule reactor/([0-9]+)/$ index.php?id=$1

Now, if instead of index.php you pull up /reactor/13/, your index.php file should see this in $_GET:

Array(    [id] => 13)

Now, for your HTML code, it's up to you to craft URLs and obey your thought-out structure.

These rewrite rules can be confusing, but they follow a logical regex pattern.

WordPress takes a stronger approach than inserting these editing .htaccess files, to where they send everything to WP, and then WP solves / routes the rest through internal rules.


This depends on what server software you're using, but if your planning on using your scripts on Apache it, usually, involves using something called mod_rewrite and specifically a .htaccess file.

I would recommend starting by reading a tutorial on this subject. As usual, Google is your friend.