I'm trying to rewrite URLs on my wordpress site to match Googles "seo friendly" policy. I want to rewrite URL's for 3 types of queries generated from search plugin:
a) Location
example.com/used-cars/?style1_nonce=5bcd0fed69&location=london&autobrand=&automodel=&modelyear=&fueltype=&priceRange=540%2C43000&autotype=&searchauto=
to be:
example.com/used-cars/london/
where london can be any location based on user search criteria.
b) Location + brand:
example.com/used-cars/?style1_nonce=5bcd0fed69&location=london&autobrand=audi&automodel=&modelyear=&fueltype=&priceRange=540%2C43000&autotype=&searchauto=
to be:
example.com/used-cars/london/audi/
where london and audi can be any location/brand based on user search criteria.
c) Location + brand + model:
example.com/used-cars/?style1_nonce=5bcd0fed69&location=london&autobrand=audi&automodel=AUDI+A1&modelyear=&fueltype=&priceRange=540%2C43000&autotype=&searchauto=
to be:
example.com/used-cars/london/audi/audi+a1/
where london, audi and audi a1 series can be any location/brand/model based on user criteria.
Search results URLs displays nonce which is different for each user. I want to skip it from "friendly URL's" so I can index these URL's in Google.
1. I have tried, without success:
Rule Pattern:
^used-cars/([^/]*)/([^/]*)/([^/]*)/?
Match:
index.php?style1_nonce=$matches[1]&location=$matches[2]autobrand=$matches[3]&automodel=$matches[4]&modelyear=&fueltype=&priceRange=540%2C43000&autotype=&searchauto=
2. Following https://codex.wordpress.org/Rewrite_API/add_rewrite_rule I have tried to test Custom Rewrites and I added the following code to my functions.php file:
function custom_rewrite_basic() {
add_rewrite_rule('^testrewrite/([0-9]+)/?', 'index.php?page_id=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');
I have flushed and regenerated the rewrite rules database but test rewrite seams not working as accessing http://example.com/testrewrite/38 returns 404.
3. Mod_Rewrite is enabled.
sudo a2enmod rewrite Module rewrite already enabled
Any advice? :)