最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

url rewriting - How does WordPress handle permalinks?

programmeradmin1浏览0评论

WordPress auto corrects the permalinks(URLs) even if it is entered incorrectly. For e.g. WordPress will land you in example/some-post even if you enter example/idontexist/some-post or even example/some

It could be that, WordPress uses RegEx like or some matching algorithm that compares from right to left and if it finds a match, it will take you to the page even if there are /.*/ left on the left. Just a guess! How does WordPress do this?

Edit: I also noticed that the .htaccess file checks for virtual file/directories using !f and !d and redirects the request to index.php on the blog folder.

WordPress auto corrects the permalinks(URLs) even if it is entered incorrectly. For e.g. WordPress will land you in example/some-post even if you enter example/idontexist/some-post or even example/some

It could be that, WordPress uses RegEx like or some matching algorithm that compares from right to left and if it finds a match, it will take you to the page even if there are /.*/ left on the left. Just a guess! How does WordPress do this?

Edit: I also noticed that the .htaccess file checks for virtual file/directories using !f and !d and redirects the request to index.php on the blog folder.

Share Improve this question asked Jun 8, 2011 at 3:01 Praveen LoboPraveen Lobo 2852 silver badges8 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 6

The redirect_canonical function in /wp-includes/canonical.php is called on any given URL and will attempt to best-guess the URL the user wanted, and redirect them to there, when a URL does not exist. It has a whole huge amount of code to do this for all sorts of common errors.

Use @JanFabry "Rewrite Analyzer" Plugin, over here in the "official" WPSE Plugin repository

It's pretty simple. WordPress makes use of LIKE operator in SQL query to guess the complete URL from the partial URL when it's a 404 page

Check this code taken from /wp-includes/canonical.php redirect_guess_404_permalink() function

$where = $wpdb->prepare( 'post_name LIKE %s', $wpdb->esc_like( get_query_var( 'name' ) ) . '%' );
发布评论

评论列表(0)

  1. 暂无评论