Add the value you want before the “meaningful” url variables (city, area, etc) to the slug like this:
"uk/([^/]*)/([^/]*)/?$" => 'index.php?city=$matches[1]&area=$matches[2]&something=$matches[3]',
This way it will only “capture” those URL variables (city, area) if “uk” is at the beginning.
A more complete example might look like this
//Set up the additional values in the "rewrite rules" array
function my_rewrites($rules){
$new_rules = array(
//uk/London/Chelsea/
"uk/([^/]*)/([^/]*)/?$" => 'index.php?city=$matches[1]&area=$matches[2]',
);
$new_rules = array_merge($new_rules, $rules);
return $new_rules;
}
add_filter('rewrite_rules_array', 'my_rewrites');
/**
* Add Rewrite Tags
*/
function my_rewrite_tags(){
//EG "London"
add_rewrite_tag('%city%','([^/]*)');
//EG "Chelsea"
add_rewrite_tag('%area%','([^/]*)');
}
add_action('init', 'my_rewrite_tags');
/**
* Use the information provided in the URL like this:
*/
function my_custom_function_which_does_stuff(){
global $wp_query;
if ( isset( $wp_query->query_vars['city'] ) ){
//EG London
$city = $wp_query->query_vars['city'];
//EG Chelsea
$area = $wp_query->query_vars['area'];
}
}
add_action( 'init', 'my_custom_function_which_does_stuff' );