Please, someone explain me how working rewrite rules in WordPress -


i have read many posts here cant understand how rewrite rules workin.

i need rewrite simple category path:

http://example.com/category/plugin-reviews/ 

to:

http://example.com/plugin-reviews/ 

for thes have used next code:

function add_rules_for_rewrite() {     add_rewrite_rule(         '/plugin-reviews/?$',         'index.php?category_name=plugin-reviews',         'top');      flush_rewrite_rules(); } add_action( 'init', 'add_rules_for_rewrite' ); 

on pge checking rules:

global $wp_rewrite;   print_r( $wp_rewrite->rules ); 

and see rule:

[/plugin-reviews/?$] => index.php?category_name=plugin-reviews 

why not working? thanx lot explaining!

this make redirect rule work way wanted if permalink settings set default

function add_rules_for_rewrite() {     add_rewrite_rule(         'plugin-reviews/?$',         'index.php?category_name=plugin-reviews',         'top'); } add_action( 'init', 'add_rules_for_rewrite' ); 

i don't think need line of code:

flush_rewrite_rules(); 

the add_rewrite_rule function created able manage redirect rules in wordpress. in simplest way explain, here's how rewriterule works

rewriterule < string match > < redirect url > < redirect , priority options >

her's article basic usage of rewrite rule in .htaccess: http://kb.mediatemple.net/questions/85/using+.htaccess+rewrite+rules#gs

if not necessary manage redirect rules using wordpress functions suggest use .htaccess convenient if you're developing plugin or theme needs manage redirect rules oftenly should use wordress functions


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -