¿Cómo tener diferentes/servidores con el mismo dominio?

4 minutos de lectura

avatar de usuario

tengo un sitio web foo.com en wordpress y quiero hacer esto foo.com/mexico, foo.com/venezuelaentrega diferente /server para cada ciudad con el mismo dominio (sin wordpress multisitio).

No estoy preguntando sobre la detección de ip por ciudad, sino por la configuración del servidor y/o dominio/dns para hacerlo.

Sé que hay otras formas de lograr esto, pero quiero saber sobre esta.

Aquí hay un ejemplo:




Esta fue mi solución:

  1. Cree un subdominio, ejemplo.foo.com que apunte a otro servidor.
  2. Cree una carpeta en el servidor principal con el nombre que quería para el enlace, por ejemplo, ‘mexico’
  3. Dentro de esta carpeta creó un .htaccess:

    Motor de reescritura activado
    RewriteCond %{REQUEST_URI} ^/mexico RewriteRule ^(.*)$ http:// ejemplo. 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’.

  • 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, 2015 at 7:25

user avatar

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...
    location /venezuela/ {            
        proxy_pass;  # ...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.

user avatar

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.

  • I know it can be done with subdomains, but i want subdirectories, like the example: vice.com/pt_br 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, 2015 at 4: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, 2018 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 2, 2019 at 10:55

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.

  • 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, 2015 at 7: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, 2015 at 14:19

¿Ha sido útil esta solución?