How WordPress permalink system works?

大兔子大兔子 提交于 2019-12-05 10:15:50

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!