10

I have a website foo.com on wordpress and I want to do this foo.com/mexico, foo.com/venezuela, delivery different /server for each city with the same domain (without wordpress multisite).

I'm not asking about to detect ip by city but server and/or domain/dns configuration to do that.

I know there is other ways to accomplish this, but want to know about this one.

Here is an example:

http://www.vice.com/pt_br

http://www.vice.com/es_co


EDIT SOLUTION

This was my solution:

  1. Create a subdomain, example.foo.com pointing to another server.
  2. Create a folder on the main server with the name i wanted for the link, for example 'mexico'
  3. Inside this folder created a .htaccess:

    RewriteEngine ON
    RewriteCond %{REQUEST_URI} ^/mexico RewriteRule ^(.*)$ http:// example. foo. com/$1 [R=301,L,P

This works for me. If i want another /server i just repeat with another name, example 'venezuela'. The subdomain name will be hide by the .htaccess and this 'example.foo.com' will look like this 'foo.com/venezuela'.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Neo
  • 195
  • 1
  • 2
  • 10
  • If your wanting different sites, for each language, then follow my answer. If your just trying to support different translated languages, then use a translation plugin and make life a lot easier for yourself. – Wade May 30 '15 at 07:25

3 Answers3

12

What you are describing is a reverse proxy.

You can set it up using apache's extension mod_proxy. Personally I haven't touched that, but my opinionated answer would be to suggest you have a look at nginx. It's a dead simple reverse proxy. You can easily run nginx in front of apache, intercepting requests and passing them on to different servers or just send html-files directly.

A nginx-config can be as simple as:

server {
    listen       80;
    server_name  example.org  www.example.org;
    location /mexico/ {
        # We could have an apache server running on another port...
        proxy_pass http://127.0.0.1:8000;
    }
    location /venezuela/ {            
        proxy_pass http://123.123.123.123:8000;  # ...or another server.
    }
    location /bulgaria/ {
        # Or just serve some static files 
        # In apache, do you set up a virtual host for this? christ.
        root /var/www/static_html;

        # If static html is all you have, what is apache even doing 
        # on your server? Uninstall it already! (As I said; opionated!)
    }
}

edit: Finding my own answer after a few years, I'd just like to add that the 301-rewrite rule that OP choose to go with adds another request that the browser must wait for before getting redirected to the real address. 301-requests are still to this day considered bad SEO, and adds some (usually minor) loading time.

ippi
  • 9,857
  • 2
  • 39
  • 50
3

You will need to use subdomains, and set the A records at your domain registrar to map each subdomain to the different servers.

Here is a related SO question. Note, it was closed, but the selected answer is what your going for: Subdomain on different host

one.yourdomain.com --> points to ServerA

two.yourdomain.com --> points to ServerB

There is info on GoDaddy's site too. If your not using GoDaddy, the process would be similar: https://support.godaddy.com/help/article/4080/managing-a-domain-names-subdomains

You go into your domain registrar where you can edit your domain settings. It will probably be in something about DNS. Your wanting to add a new "A Record".

Some registrars simply let you put in "yoursubdomain", the IP of the server, and the TTL (Time To Live).

So enter your the subdomain for your first one, the IP of the server you want it to point to, and the TTL (if it asks) which is usually 3600.

Then add another "A Record", only for your other subdomain, the IP for that server, and TTL.

Repeat for however many subdomains and servers you need.

Community
  • 1
  • 1
Wade
  • 3,757
  • 2
  • 32
  • 51
  • I know it can be done with subdomains, but i want subdirectories, like the example: http://www.vice.com/pt_br http://www.vice.com/es_co So it will be a subdirectory pointing to a server and in that server is a worpress installation. – Neo Sep 25 '15 at 04:00
  • Hi Neo, Have you achieved what you wanted to do? I have the same challenge as of yours. Kindly share the solution. – erTugRul May 22 '18 at 11:17
  • @erTugRul Hey, I never noticed your question. Hope you get the solution from the question, I updated it as soon as I did it. – Neo May 02 '19 at 10:55
1

your solutions is:

1.You can use A record & subdomains for every server.

2.You can use your webserver configuration to relay user to destination servers (Apache,NGINX & etc)

But here I see you'r asking about Wordpress from multi server. You can only have multi server for your static contents (CDN), but your database must be in one place except you want to use cloud DB.

Milad Abooali
  • 686
  • 1
  • 13
  • 30
  • You can allow remote servers to connect to your database, without a cloud db solution. By default, only localhost can connect, but you can easily add (whitelist) other hosts. – Wade May 30 '15 at 07:27
  • This is not secret, as I say he can use multi servers for static contents, It's mean the db is single and on the main server. if he want to run single database on multi server he need cloud db. otherwise he can use method 1 or 2. – Milad Abooali May 30 '15 at 14:19