admin管理员组

文章数量:1410674

Following is example of what we are looking for. We're trying this in wordpress and we require all parameters as a variable


Example 1 : /?parent=abc

Need this :


Example 2 : /?parent=abc&sub1=abc&sub2=abc

Need this :


funtion.php code OR .htaccess rule any suggestion.

Thanks in advance

Following is example of what we are looking for. We're trying this in wordpress and we require all parameters as a variable


Example 1 : http://example/tno/?parent=abc

Need this : http://example/tno/abc


Example 2 : http://example/tno/?parent=abc&sub1=abc&sub2=abc

Need this : http://example/tno/abc/abc/abc


funtion.php code OR .htaccess rule any suggestion.

Thanks in advance

Share Improve this question edited Nov 20, 2019 at 16:07 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Nov 20, 2019 at 13:42 ViralViral 1033 bronze badges 4
  • to customise URL look that : wordpress.stackexchange/questions/352189/… – Kaperto Commented Nov 20, 2019 at 14:06
  • How do you know it's not working? Please show us your code. – fuxia Commented Nov 20, 2019 at 14:17
  • function archive_rewrite_rules() { add_rewrite_rule( '^/(.*)/(.*)/(.*)?$', 'index.php?post_type=client&parent=$matches[2]&sub1=$matches[3]&sub2=$matches[4]', 'top' ); } add_action( 'init', 'archive_rewrite_rules'); example/tno/… example/tno/helloenergy/zelf-aan-de-slag/mentaal – Viral Commented Nov 20, 2019 at 14:45
  • @VipulGhetiya Please edit your question, and add that code. :) – fuxia Commented Nov 20, 2019 at 16:07
Add a comment  | 

2 Answers 2

Reset to default 0

Into wordpress function file add following code and check it.

add_filter('query_vars', function( $vars ){
    $vars[] = 'parent'; 
    return $vars;
});

function archive_rewrite_rules() {
    add_rewrite_rule(
    '^(.*)/(.*)/?$',
    'index.php?post_type=client&name=$matches[1]&parent=$matches[2]',
    'top'
    );

    add_rewrite_rule(
    '^(.*)/?$',
    'index.php?post_type=client&name=$matches[1]',
    'top'
    );
    //flush_rewrite_rules(); // use only once
}

add_action( 'init', 'archive_rewrite_rules' );

Simply, go to Dashboard Setting > Permalink and change to "Post name" link type or you can use a plugin like enter link description here And for redirect you can use this plugin: enter link description here

本文标签: url rewritingWordPress URL redirect and replacequestion mark