Wordpress add_rewrite_rule for page redirecting incorrectly

admin

Administrator
Staff member
I am trying to add custom rules using wordpress's add_rewrite_rule function, but they don't work. The weird thing is that the rules are added and match my URL whenever I inspect them with the <strong>Monkeyman Rewrite Analyzer</strong> plugin.

When I try to access the page, it redirects to an incorrect location.

Here is my code:

Code:
add_rewrite_tag('%cc%','([a-zA-Z]+)');
add_rewrite_tag('%id%','([0-9]+)');

add_rewrite_rule('job-details/([0-9]+)$', 'index.php?pagename=jobs&amp;cc=show&amp;id=$matches[1]', 'top');

global $wp_rewrite;
$wp_rewrite-&gt;flush_rules();

As for my URLs, if I try to access the URL site.com/job-details/1 , it redirects me to /jobs/ , which is the page associated with my plugin.

Here is my .htaccess file

Code:
RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]