Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have different /servers with same Domain?

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'.

like image 455
Neo Avatar asked May 30 '15 04:05

Neo


1 Answers

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.

like image 199
ippi Avatar answered Oct 12 '22 00:10

ippi