Rewrite rules priority
I’d say either change the order, put (2) before (1), or be more specific with the rules. E.g. from/([a-zA-Z]*)/?
I’d say either change the order, put (2) before (1), or be more specific with the rules. E.g. from/([a-zA-Z]*)/?
You need to either go into Settings -> Permalinks and click Save Or if you’re doing this programmatically you need to use flush_rewrite_rules(), but make sure this is only used when you activate/deactivate the plugin, DON’T set this in code that runs (like in init, or on every page load): https://developer.wordpress.org/reference/functions/flush_rewrite_rules/ register_deactivation_hook( __FILE__, ‘flush_rewrite_rules’ ); … Read more
I am new to WordPress rewrites, so after some StackExchange reading i have figured it out. All rewrites should be passed to index.php, then i can call the page that i want to redirect to, like this: function custom_rewrite_basic() { add_rewrite_rule( ‘validate_data.php’, ‘index.php?pagename=validate-data’, ‘top’ ); } add_action( ‘init’, ‘custom_rewrite_basic’ ); In addition i wanted to … Read more
Hope this will work out for as it did for me. add_filter(‘rewrite_rules_array’, ‘insert_custom_rules’); add_filter(‘query_vars’, ‘insert_custom_vars’); function insert_custom_vars($vars){ $vars[] = ‘main_page’; return $vars; } function insert_custom_rules($rules) { $newrules = array(); $newrules=array( ‘page-name/(.+)/?’ => ‘index.php?pagename=page-name&main_page=$matches[1]’ ); return $newrules + $rules; } So, with the help of get_query_var() function, we can get value from url and use accordingly. … Read more
The problem is in your rewrite rules function, it should be function num_rewrite_rule(){ add_rewrite_rule( ‘test/([0-9]+)/?$’, ‘index.php?pagename=test&num=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘num_rewrite_rule’ ); Reference add_rewrite_rule NOTE: Always remember to flush your permalinks by visiting **Settings – Permalinks **
I figured it out. I put these rewrite rules in .htaccess: RewriteCond %{QUERY_STRING} ^id=([^/]*)&n=([^/]*)$ RewriteRule ^show/?$ /show\/%1\/%2\/? [R=301,L]
Theme’s functions.php is not the best place to do these sort of URL rewrites. Why?: because in that case WordPress will be fully loaded and then redirected to a new link and then fully loaded again to show the page. That’s a lot of delay for a page view. Instead of that, you may use … Read more
Ok managed to figure this out, instead of adding action for a rewrite. Because what I was wanting to rewrite was a taxonomy i should have been using something like this : ‘rewrite’ => array(‘slug’ => ‘listings/make’, ‘product_make_model’ => false) When registering the taxonomy, which basically rewrites the slug as the taxomomy is created/registered. Works … Read more
This might be a permalink issue. Sometimes when things like HTTPS get turned on, you need to flush permalinks to get URL’s and rewrites working again. Head to permalinks (settings > permalinks) and just hit the save button and see if that fixes the issue there.
I installed Monkeyman Rewrite Analyzer https://wordpress.org/support/plugin/monkeyman-rewrite-analyzer/ which helped a great deal. I saw this referenced on Jan Fabry’s detailed answer on this post which also helped me. First thing that I found out with the plugin was that my rewrites weren’t actually getting added; they didn’t appear in the logic. It turns out the add_rewrite_rule() … Read more