My requirement is to do SEO Friendly URL for an existing site in Wordpress.

For example,

Current URL: http://test.com/test/?pid=19971 that is the page "test" is rendering the data from some custom plugin.

My new SEO URL : http://test.com/brand/sub_category/product_name Here, Brand, Sub_category and product_name is fetched from the pid. I am populating the data using the following rewrite rule from functions.php,

add_rewrite_rule(MY_DYNAMICALLY_POPULATED_URL.'$ page-test.php?brand='.$brand_name.'&sub='.$sub_category.'&pname='.$product_name.' [L]', 'top');

In this code, the page-test.php is placed in the root directory and the data is rendered from that file by passing the brand_name, sub_category and productname to fetch the pid. So based on the pid each product page is rendered.

This code is working fine for me, When I save the data automatically the data is written in .htaccess and page is rendering with the new SEO URL.

But when my client needs it to do it by FALLBACK in Apache instead of add_rewrite_rule due to some load balancing issue.

So can anyone help me how to do the same with Fallback resource.

  • I had tried fallback rule couple times with WP and always had obscure issues. It plain doesn't work too well (don't know enough to say with WP or in general).
    – Rarst
    Apr 21, 2014 at 17:37
  • Actually the dynamic URLs should not be written into htaccess. Without writing there I need to render the contents. Is there any possibility like that.? Apr 21, 2014 at 17:40
  • Finally using the "page_rewrite_rules" filter I have done it without writing it to .htaccess file. Thanks for all your support. :) Apr 22, 2014 at 10:09

1 Answer 1


This fixed my issue.

function my_query_vars($vars)
$my_vars = array( 'PARAMETERS' );
return array_merge($my_vars, $vars);
add_filter('query_vars', 'my_query_vars');

function my_rewrite_rules($rules)
global $wp_rewrite;
$my_page = 'PAGESLUG';
$my_rule = array( 'URL/?' => 'index.php?pagename=' . $my_page . '&school_type=$matches[1]' );
return array_merge($my_rule, $rules);
add_filter('page_rewrite_rules', 'my_rewrite_rules');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.