I know this question has been asked so many times but I didn't find any working solution or example which I can use to fix my problem.
I have been working on a client site. There are two similar sites, one for their own country and second for other country's visitors.
Their main site hosted in the root of the server and second site hosted in the subfolder.
Now what I want is a dynamic URL rewrite for the second site which is hosted into a subfolder with the country code of the visiting user.
For e.g.
http://example.com
http://example.com/subfolder/
are the URLs.
I want this http://example.com/subfolder/
to be changed into this http://example.com/country_code/
where country_code
is visitor country code in ISO format getting through PHP function.
So if the user is from United States the subfolder
must be changed into us
, the new URL should be now http://example.com/us/
.
I want this to work for all types of pages, whether its a page, post, category, tag or author page.
So again, http://example.com/subfolder/any-type-of-url/
=> http://example.com/country_code/any-type-of-url/
Remember country_code
is user/visitor country code in ISO format.
Let me know if someone needs more information on this. Thanks in Advance.
PS: I tried to achieve this using add_rewrite_rule()
function available in WP.
.htaccess
file, I have PHP function for it, btw I can get country code in.htaccess
file too, see the answer here