Question

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

For example,

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

My new SEO URL : http://localhost/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.

Was it helpful?

Solution

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');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top