Every guide seems to be simple and straight-forward—just place a small block of code into functions.php and then flush the rewrite rules by going to permalinks and saving. But my function refuses to be acknowledged even with the most lenient descriptors possible.
I have slowly whittled down the code I’m using from this:
function new_rewrite() {
add_rewrite_rule('^u/(.+)/?$','index.php?pagename=user-profile&user=$matches[1]','top');
}
add_action('init', 'new_rewrite');
to this completely catch-all version that proved to me something is seriously wrong here:
function new_rewrite() {
add_rewrite_rule('.*','index.php','top');
}
add_action('init', 'new_rewrite');
When I use the above code—which as far as makes sense to me should take anything given to it and return the homepage—instead it is completely ignored and everything works the exact same way as before I tried to write any rules.
And let me reiterate: I have placed this in functions.php where I’ve added plenty of other functions such as add_custom_query_var to great success and I have also been flushing the rewrite rules constantly.
What could possibly be going on here?
WordPress use the htaccess located at the root of his installation – not the root of the website server folder – so the htaccess that WP will override is the one that is as the same level as wp-config.php.
By default the WP htaccess contains those two comments:
WordPress use them to know where he should add the rules generated by
add_rewrite_rule
– it is sometimes usefull to move this comments to make rules more higher or lower compared to some other custom rules.