As per the answer provided in How to create custom URL routes? I have created the rewrite rule using the same function provided.
add_action( 'init', 'wpse26388_rewrites_init' );
function wpse26388_rewrites_init(){
add_rewrite_rule(
'gallery/([0-9]+)/?$',
'gallery?custom_gallery_id=$1',
'top' );
}
After the flushing of the rules .htaccess
file was having the following rule :
RewriteRule ^gallery/([^/]+)/?$ /wordpress/gallery?custom_gallery_id=$1 [QSA,L]
upto this point everything was fine then I tried to make some modifications in the rule like
add_action( 'init', 'wpse26388_rewrites_init' );
function wpse26388_rewrites_init(){
add_rewrite_rule(
'topic/([^/]+)/([^/]+)/gallery/([0-9]+)/?$',
'gallery?custom_gallery_id=$3',
'top' );
}
this doesn’t seems to be working at all. can anybody help me over this?
thanks in advance.
first, you need to add your
custom_gallery_id
to query vars if you haven’t already:for your rewrite rule, you need to load a WordPress object– a page, a category, etc., and all internal rewrites must point to index.php. if topic, place, and new delhi are all pages, it would look something like this:
also try out this plugin for analyzing and testing your rewrite rules.