mdnba50
mdnba50

Reputation: 379

Wordpress add_rewrite_rule not working

I have the page my-page, which has page id 38 .

I want to turn

http://www.example.com/my-page?q=page-title

to

http://www.example.com/my-page/page-title

I've tried adding this rewrite rule to functions.php. I keep getting page not found.

function custom_rewrite_tag() {
  add_rewrite_tag('%my-page%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);


function custom_rewrite_rule() {
  add_rewrite_rule('^my-page/([^/]*)/?','index.php?page_id=38&q=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);

How do i solve?

Upvotes: 0

Views: 4859

Answers (1)

CaldwellYSR
CaldwellYSR

Reputation: 3196

Look into the flush rewrite rules function.

This function is useful when used with custom post types as it allows for automatic flushing of the WordPress rewrite rules (usually needs to be done manually for new custom post types). However, this is an expensive operation so it should only be used when absolutely necessary

Upvotes: 1

Related Questions