add_rewrite_url get parameters are empty
<p>I used add_rewrite_rule to redirect a nice URL to the right page.
This is the rule:</p>

<pre><code>add_rewrite_rule('^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?','index.php?pagename=auto&amp;id=1234', 'top' );
</code></pre>

<p>So if I go to the following URL: website.com/cars/brand/model/car/1234 It wil go to the page with pagename auto. </p>

<p>On this page is a shortcode that needs to get this id. If I echo $_GET['pagename'] it prints 'auto'. But if I print $_GET['id'] it contains nothing. Why can't I get that value in the shortcode??</p>

<p>This rule works fine:</p>

<pre><code>add_rewrite_rule('^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?','index.php?pagename=auto&amp;id=' . $_GET['id'], 'top' );
</code></pre>

<p>But I want something like this:</p>

<pre><code>add_rewrite_rule('^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?','index.php?pagename=auto&amp;id=$matches[5]', 'top' );
</code></pre>

<p>I don't know why the $matches is empty.</p>

<p>Complete code:</p>

<pre><code>function redirectUrls() {
    flush_rewrite_rules();
    add_rewrite_rule('^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?','index.php?pagename=auto&amp;id=1234', 'top' );
}
add_action('init', 'redirectUrls');
</code></pre>

<p>I put this code in my plugin</p>

<p><strong>EDIT (ANSWER)</strong>
Oke I've used this tutorial and it works: <a href="http://www.janes.co.za/wordpress-permalinks-and-custom-_get-variables/" rel="nofollow">http://www.janes.co.za/wordpress-permalinks-and-custom-_get-variables/</a></p>

<p>I also used the answer of @Sacroma</p>

<pre><code>function add_query_vars($aVars) {
    $aVars[] = "id";    // represents the name of the product category as shown in the URL
    return $aVars;
}
add_filter('query_vars', 'add_query_vars');

function add_rewrite_rules($aRules) {
    $aNewRules = array('^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$' =&gt; 'index.php?pagename=auto&amp;id=$matches[5]');
    $aRules = $aNewRules + $aRules;
    return $aRules;
}

add_filter('rewrite_rules_array', 'add_rewrite_rules');
</code></pre>

<p>Now I can use the get_query_var("id")</p>