How do I remove a rewrite rule?
the flush_rewrite_rules() function will delete and regenerate the rewrite rules. you can also visit the permalinks settings page in admin and save, that triggers a flush as well.
the flush_rewrite_rules() function will delete and regenerate the rewrite rules. you can also visit the permalinks settings page in admin and save, that triggers a flush as well.
I found the solution on the Codex just after posting on the site and this is the code I was looking for: function my_htaccess_contents( $rules ) { $my_content = <<<EOD \n # BEGIN My Added Content # Protect wpconfig.php <Files wp-config.php> Order Allow,Deny Deny from all </Files> # END My Added Content\n EOD; return $my_content … Read more
Maybe I did not get this very well, but if you need to just remove ‘foo’ from query vars would not be much more simple to use the ‘request’ filter and remove the var from there? Code needed: add_filter(‘request’, function($query_vars) { return array_diff_key($query_vars, array(‘foo’=>”)); }); It: runs on main query only remove the var for … Read more
You can add your own rewrite rule which will let you tweak the query via URL parameters: add_action( ‘init’, ‘rewrite_photo_url’ ); function rewrite_photo_url() { add_rewrite_rule( ‘photos/([^/]+)/?$’,’index.php?page=photos&photo_id=$matches[1]’, ‘top’ ); } If you need to use a custom variable, i.e. ‘photo_id’, you have to register the variable so it will be recognized by the query: add_filter( ‘query_vars’, … Read more
add_rewrite_rule() allows you to turn the pretty url into variables. numbers: (\d*) section: /rid/ or /pageid/ slug: ([a-zA-Z0-9-]+ Here is a class to register the rewrite and handle the request if a match has been found. <?php if ( ! class_exists( ‘CPTURLRewrite’ ) ): class CPTURLRewrite { const ENDPOINT_QUERY_NAME = ‘pageid’; const ENDPOINT_QUERY_PARAM = ‘__pageid’; … Read more
10up engineering best practices as a great example on how to achieve that. You basically add a new rewrite tag and a new rewrite rule and then using the template_redirect action you return your custom action. Here is the code: add_action( ‘init’, function() { add_rewrite_tag( ‘%model%’, ‘([^/]+)’ ); add_rewrite_rule( ‘cars/([^/]+)/?’, ‘index.php?model=$matches[1]’, ‘top’ ); } ); … Read more
To be added on init: To register your custom variable (‘id’ in the question) add_rewrite_tag(‘%mycustomvar%’,'([^&]+)’); To create a re-write rule: add_rewrite_rule(‘^product/([0-9]{1,})/?’,’index.php?p=4&mycustomvar=$matches[1]’,’top’) 4 is the id of the ‘product’ page. You will need to flush rewrite rules once after adding these (go to Permalink settings page) You can get the value of mycustomvar: get_query_var( ‘mycustomvar’ ). … Read more
What I understand from the above is you have .htaccess file and also correct code written in to the same file but still getting 404 issue. Let me tell you why. Your server not allowing .htaccess file to read or override permission. So how can you give this permission? Open your Apache httpd.conf file serch … Read more
You will need to enable verbose page rules, which make sure that all pages are explicitly defined (instead of using a generic rule). But in addition to that, you need to move these page rules above the taxonomy rules. This is a fairly recent change, I believe it was between 3.0 and 3.1. I explain … Read more
Create a Page Template Add a new page and give it the slug stores Add A Public Query Variable add_filter(‘query_vars’, ‘add_state_var’, 0, 1); function add_state_var($vars){ $vars[] = ‘state’; return $vars; } Add a rewrite rule This will direct your request to your stores page. add_rewrite_rule(‘^stores/([^/]*)/?’,’index.php?post_type=page&name=stores&state=$matches[1]’,’top’); Within your Template You can access your state variable as … Read more