Board Deng: How WordPress uses Wp_rewrite to implement custom pseudo-static, non-301 redirection.

Source: Internet
Author: User
Tags vars

Today, I want to realize through WordPress

Http://hcsem.com/a?h-1

Pseudo-Static is

Http://hcsem.com/a-1.html

Find a lot of information, finally fix.

Just add the following code to the functions.php file:

Add_filter (' Rewrite_rules_array ', ' my_insert_rewrite_rules '); Add_filter (' Query_vars ', ' my_insert_query_vars '); Add_action (' wp_loaded ', ' my_flush_rules ' );//Flush_rules () If our Rules is not yet includedfunctionMy_flush_rules () {$rules= Get_option (' Rewrite_rules ' ); if( !isset($rules[' A-(. *). html$ '] ) ) {        Global $WP _rewrite; $WP _rewrite-Flush_rules (); }}//Adding a new rulefunctionMy_insert_rewrite_rules ($rules ){    $newrules=Array(); $newrules[' A-(. *). html$ '] = ' index.php?pagename=a&h= $matches [1] '; return $newrules+$rules;}functionMy_insert_query_vars ($vars ){    Array_push($vars, ' H '); return $vars;}

How to get H value in page-a? Copy the following code:

Echo $wp _query->query_vars[' h '];?>

Board Deng: How WordPress uses Wp_rewrite to implement custom pseudo-static, non-301 redirection.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.