0

I'm wonder how WordPress or some other websites rewrite URLs without any identifier mentioned.

for example in WP when i open Permalink Settings can select a custom URL format as below.

http://localhost/wordpress/sample-post/

Just post title has been mentioned and there is no way to know the Post ID apparently. Now thinking of how WP know which post have to be loaded ?

What i think myself is that this formatted URL has not been rewritten and just is a sample that WordPress use to rewrite every post after i create it. So every time i write a post it adds a new rewrite to .htaccess file.

But this solution is not logical and make us to have a dirty htaccess file and is very hard to maintenance because a lot of conflicts are likely.

Another solution is to think that there is no regular rewriting at all, and WP is processing URL itself, so when current URL matches to sample URL it know that's time to load an specific post.

This is feasible too, but the main problem still remained that how it know which Post have to be loaded ? Is it searching on DB using title ?! So how it can guarantee that titles are unique ?

That's a big challenge in my life ;)

4

1 回答 1

1

Wordpress 的wp_post表有一个名为 的列post_name,它用于存储帖子标题的唯一 url 友好版本。它使用该列的值搜索数据库。

这通常称为 a slug,并且它必须是唯一的。

于 2012-12-30T08:26:39.783 回答