Custom rewrite rules for a $_GET request

The question:

Assuming I have this URL:

How can I change it to a nice URL that looks like:

using WP’s URL rewriting system?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

First add get to query vars array:

function add_query_vars_wpa12572($vars) {
    $vars[] = 'get'
    return $vars;

add_filter('query_vars', 'add_query_vars_wp12572');

then add the rewrite rule

function author_rewrite_rules_wpa12572( $wp_rewrite ) {
  $newrules = array();
  $new_rules['get_(d*)$'] = 'index.php?get=$matches[1]';
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment