add_rewrite_rule not working for me
Have you tried adding the third parameter to that call? add_rewrite_tag( ‘%make%’, ‘([^/]+)’, ‘make=” );
Have you tried adding the third parameter to that call? add_rewrite_tag( ‘%make%’, ‘([^/]+)’, ‘make=” );
Set the option that stores the rewrite configuration to autoload via the 4th argument of add_option: add_option( ‘my_plugin_option’, $my_plugin_options, ”, ‘yes’ ); It’ll get loaded and cached with the query that already runs on every page load, so it’s a non-issue. Then you can add your rewrite rules on the correct hook, which is init, … Read more
Instead of index.php/reco/?b=$1, try this: “$wp_rewrite->index?pagename=reco&b=” . $wp_rewrite->preg_index( 1 ) You should also append a $ to your reco/([^/]*)/? regex to ensure the rule only matches the entire path, and not just the beginning. Then flush your rules afterwards (just re-save your permalink settings in admin). Update: Try using the page_rewrite_rules filter instead, and use … Read more
From performance point of view what takes time is matching URL against generated (and stored persistently so it’s not rebuilt continuously) list of regular expressions. Since URLs are (most of the time) insignificantly short in text volume the amount of those regular expression rules has most impact on performance. Unless you generate unreasonably many rules. … Read more
This fixed my issue. function my_query_vars($vars) { $my_vars = array( ‘PARAMETERS’ ); return array_merge($my_vars, $vars); } add_filter(‘query_vars’, ‘my_query_vars’); function my_rewrite_rules($rules) { global $wp_rewrite; $my_page=”PAGESLUG”; $my_rule = array( ‘URL/?’ => ‘index.php?pagename=” . $my_page . “&school_type=$matches[1]’ ); return array_merge($my_rule, $rules); } add_filter(‘page_rewrite_rules’, ‘my_rewrite_rules’);
I found the correct url and patched the rewrite and it works perfectly now! This is what I ended with! add_rewrite_rule(‘^vehicle-make/([^/]*)/([^/]*)/?’,’index.php?vehicle-make=$matches[1]&sort=$matches[2]’,’top’);
Try this : function change_post_type_link( $link, $post = 0 ){ if ( $post->post_type == ‘questions’ ){ return home_url( ‘questions/’. $post->post_name .”https://wordpress.stackexchange.com/”. $post->ID ); } else { return $link; } } add_action( ‘init’, ‘change_rewrites_init’ ); function change_rewrites_init(){ add_rewrite_rule( ‘questions/([a-z-]+)/([0-9]+)?$’, ‘index.php?post_type=questions&p=$matches[1]&postid=$matches[2]’, ‘top’ ); } Here post slug is attached after questions in the URL. For example questions/q-slug/45. … Read more
It seems the problem is not with add_rewrite_rule rather with the .htaccessfile for the multi site. One of the test addresses was http://example.com/foobar/def/whatever.php Here’s a part of the htaccess which causes the result (Line 2) RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] If I comment this line out it works … Read more
The second argument of add_rewrite_rule is not a path, it the query string you want WordPress executes. This should work for example.com/sub-folder/thepage/ (change page_id with ID of your page): add_rewrite_rule(‘thepage/’, ‘index.php?page_id=12’); or with page slug: add_rewrite_rule(‘thepage/’, ‘index.php?pagename=thepage’); As you have WordPress in a subdirectory and you want to rip out the directoy name, you have … Read more
Change the Settings -> Permalink to Custom Structure /%category%/%postname%/ Now while editing the post, check only the subcategory and now the parent category is nested within the URL automatically.