WordPress pagination pseudo-static with html suffix, wordpress
Problem
When there are page shards in the document, wordpressgenerates a persistent link in the form of page.html/2. The previous section is the $ link of the article, and the numbers below represent the page number $ number. So the question is, mining ...... No. Logically, is this an html file or a directory?
Ugly
Adding a slash (/) and a number to the static file ".html" is confusing. This is only a second. What's important is that the search engine does not include such a strange link, which is unacceptable, what I write is very important at the beginning and end, and cannot be ignored because of a single page.
Not included
From this article, Google indexed the content on the first page of the search article:
Search for the content on the second and third pages of the article, which is not included at all:
Solution
So I decided to generate links and parse rules for DIY WordPress.
Ideas
Use filter wp_link_pages_link to rewrite the paging link/123456into page-201712345620..html.
Reuse the rewriteruleof the wordpress1_server to restore page-00001234560000.html to/123456
Hooks redirect_canonicalto prevent the force redirect of wordpressfrom page-201712345620..html to/123456.
Generate pagination html suffix links
Add the following to the WordPress topic:
Class Rewrite_Inner_Page_Links {var $ separator; var $ post_rule; function _ construct () {$ this-> separator = '/page-'; // (. + ?) /([^/]+).Html (/[0-9] + )? /? $ This-> post_rule = '(. + ?) /([^/] +) ('. $ This-> separator.' (%0-9%%%%%%%%.html /? $ '; If (! Is_admin () | defined ('doing _ AJAX '): add_filter ('wp _ link_pages_link', array ($ this, 'inner _ page_link_format '), 10, 2 ); // for inner pages add_filter ('redirect _ canonical ', array ($ this, 'canceled _ redirect_for_paged_posts'), 10, 2); endif; if (is_admin ()): add_filter ('rewrite _ rules_array ', array ($ this, 'pagelink _ rewrite_rules'); endif ;} /*** modify the format of the post paging link * @ param string $ link * @ param int $ number * @ Return string */function inner_page_link_format ($ link, $ number) {if ($ number> 1) {if (preg_match ('% <a href = ". *\. html/\ d * "% ', $ link) {$ link = preg_replace (" % (\. html)/(\ d *) % ", $ this-> separator. "$2 $1", $ link) ;}return $ link;}/*** adds a redirection rule for the new link format to remove the redirection rule for the original paging link, preventing Repeated inclusion of the ** original access link will return 404 * @ param array $ rules * @ return array */function pagelink_rewrite_rules ($ rules) {$ new_rule [$ this-> po St_rule] = 'index. php? Name = $ matches [2] & page = $ matches [4] '; return $ new_rule + $ rules ;} /*** disable WordPress from redirecting page paging links to the original format * @ param string $ redirect_url * @ param string $ requested_url * @ return bool */function cancel_redirect_for_paged_posts ($ redirect_url, $ requested_url) {global $ wp_query; if (is_single () & $ wp_query-> get ('page')> 1) {return false;} return true ;}} new Rewrite_Inner_Page_Links ();
As a result, the paging link like the http://www.domain.com/program/tokyodaigaku.html/2/ is converted into a link like a http://www.domain.com/program/tokyodaigaku/page-2.html.
Note: My pseudo-static rules are/% category %/Your postnameapps.html. If your rules are different, modify the code or pseudo-static rules on your own.
Rewrite URL rules
The result is a heartless 404 error:
Use server Rewrite Rules
If it is SAE, add the following in the first line of config. yaml:
Copy codeThe Code is as follows:-rewrite: if (! Is_dir () & path ~ "(. + ?) /([^/] +) (/Page-(%0-9%%%%%%%%%.html /? $ ") Goto" index. php? Name = $2 & page = $4"
If not, you can use the rewrite_rules that comes with WordPress:
Log on to the background -- set -- fixed link:
Save the changes without filling in anything. The code automatically adds a rule to the database:
Copy codeThe Code is as follows: "(. + ?) /([^/] +) (/Page-(%0-9%%%%%%%%%.html /? $ "=>" Index. php? Name = $ matches [2] & page = $ matches [4]"
Final Effect
You can refer to the second page for both http://www.domain.com/program/tokyodaigaku.html/2/ and http://www.domain.com/program/tokyodaigaku/page-2.html.
Put the specific effect on the second page and test the effect of the paging suffix.
Okay, the basic functions have been implemented. Do you understand them? If you have any questions, please leave a message.