How to have different /servers with same Domain? - php

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:
Create a subdomain, example.foo.com pointing to another server.
Create a folder on the main server with the name i wanted for the
link, for example 'mexico'
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'.

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.

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.

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.

Related

How to handle incoming CNAME records and point to the specified URL?

I have looked everywhere for something on this but can't seem to find anything.
After setting up the CNAME record of a domain (i.e. user_domain.com) to point to my own example.com, what would be the next step? How would I get it to point to example.com?
I believe that I will need to do something on my end in order to handle these domains but I can't find any tutorials on how to do so.
The error that is received when visiting user_domain.com is:
user_domain.com’s server DNS address could not be found.
For the record, I am using Ubuntu, Apache and PHP. Would something need to be done to the .htaccess file?
CNAME
www example.com
Overall
I am trying to let users point their own domain to example.com
What would be the next step after setting up the CNAME record?
I would appreciate any help, thanks!
You either have to:
Configure your Apache with name-based virtual hosts and have it listen explicitly for the new domain via the ServerAlias directive.
Or:
Configure your Apache for IP-based hosts. It will serve the example.com content for whatever domain name is pointed at it.
Or:
Configure your Apache with name-based virtual hosts and have it listen implicitly for the new domain by making sure example.com is the first vhost listed in the config. This will make example.com the "default" service for IP-based requests. (Not 100% sure about this one, but this is how I recall Apache behaving.)

Redirect and URL Mask all non-existing/existing subdomains to homepage

A website example.com has one subdomain a.example.com. The point here is I want to redirect all existing and non existing subdomain (ex- b.example.com) to example.com without changing URL(URL MASK). To explain it more further, when a user enters b.example.com he must see example.com on his screen but URL must not change from b.example.com --> example.com. I think its possible from .htaccess file but I failed to achieve it.
Do I need to configure virtual host. Since I only have access to .htacces, I wish I can get it done
You need to have two things configured correctly:
A DNS entry with wildcard (*.example.com -> your server IP)
A virtual host with wildcard alias (ServerAlias *.example.com)
Then there is nothing to do in .htaccess. .htaccess alone can't do what you want. And please note also that this could be SEO-toxic (duplicate content), but it depends on your use case.
As you do not have access to virutal hosts config, may be you could go with subfolders instead of subdomains.

changing my ip based url to name based url

basically i have my website under 91.xx.xx.76/mywebsite in folder /var/www/mywebsite
and i want the user to type www.mywebsite.com, i have search some methods in doing so but doesn't actually solve it. they say to create a file under sites-available then enabled it
i have created file under sites-available and also enabled it using a2ensite mywebsite, then restarted apache2 using service apache2 restart then i try to load www.website.com but it loads nothing..
any help?
thanks
To use "name based URLs", you need to register the domain you wish to use in the global Domain Name System (DNS). Just setting some configuration in your own server is not enough; anybody could do that, which means there could be any number of people claiming the domain www.website.com at the same time. That's not how it works.
Find yourself a domain name registrar whom you'll wire a small amount of money in exchange for registering your desired domain. This purchases you the rights to set the DNS configuration of said domain to point its A record to your server's IP address.* This is what enables you to resolve www.website.com to your server. Then you only need to configure your server appropriately to serve requests for www.website.com.
* More correctly, it purchases you the right to set the NS record of the domain to point to a name server you control on which you can set any number of DNS records you want, including the A record. Most registrars also offer a name server as part of the deal of purchasing a domain, but those are actually separate things.

domain mapping: php or nodejs & nginx

I want to automate a process so that my clients can sign up on their own to my application, insert them own domain name and i can map the domain name to their subdomain.
For example, they have a subdomain called mappable.example.com and they have a domain name called mappable.com
I have two questions:
1. How do you create a subdomain for them in php and/or nodejs called mappable.example.com
2. How do you map the domain name to mappable.com
I'm using nginx as a web server. Do I have to use php or nodejs to manually edit the nginx config files?
I'm assuming you own example.com, they own mappable.com, and you want to allow them to use their domain mappable.com to access your subdomain mappable.example.com hosted on your server.
There are a few steps you'll need to do for this.
Set up wildcard DNS with your domain registrar so that all sub-domains will come to your one server.
Set up wildcard domain handling in nginx's conf on your one server so that all requests are sent to your code. You can do this using an underscore as the server name to make it the default server.
In your PHP code, you can check the headers to determine what domain the request is coming in through. Do a dump of $_SERVER to see what's in there. You will then know if the request came to mappable.com, mappable.example.com, etc...
Once you are in PHP with the domain or subdomain that was requested, you can act accordingly. You'll want to store the mapping of domain to subdomain in a database most likely. Additionally, you'll have to tell your users that they need to set up a cname, for example a cname of "mappable.com" to "mappable.example.com".
I think that should do what you need.

Can I dynamically create subdomains (PHP, .htaccess) with GoDaddy Hosting?

I am trying to use a combination of .htaccess and PHP to create subdomains on-the-fly on my GoDaddy Hosting account. I've run into a problem of trying to modify the zone using the wildcard asterisk. I am not at all familiar with how this works and have only found the zone stuff about the domain by exploring the domain manager extensively. I'm not sure I know what I'm doing. I'm slightly more acquainted with .htaccess, although it's still a big challenge for me to write RegEx.
I've researched another tutorial that will use .htaccess to reroute a subdomain to a folder in the root of my domain (e.g. sub.domain.com to domain.com/sub). Here's my code:
#Grab the subdomain from the domain
RewriteCond %{HTTP_HOST} ^([^.]+).MY-DOMAIN.com$
#Make sure the subdomain is not www or example
RewriteCond %{1} !^(www)$
#Check if the directory actually exists before we go there
RewriteCond /home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/%1 -d
#This stops it from looping
RewriteCond %{REQUEST_FILENAME} !^/home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/
#Finally, this is the actual rewrite
RewriteRule (.*) /home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/%1 [L]
As of right now, I've done the following:
Logged into GoDaddy Domain Manager.
Went to Tools > DNS Manager.
Opened the Zone File Editor for my domain.
Added an A (Host) Record with Host Name * and in Points to IP Address I copied the value from the # entry's IP address, since that should be the same as my domain...?
Now, after waiting until the nameservers or whatever updated and propogated and stuff, I get a 403 error when I try to access a subdomain.
Any suggestions?
DNS is only 1 part of the configuration. You need to have a ServerAlias for *.mydomain.com in the configuration for the virtual host in Apache, otherwise Apache will not have any idea where to route requests for *.mydomain.com - which means the .htaccess never has a chance to work at all.
If GoDaddy provides a way to manually edit your virtual hosts' directives, or at least the ability to add server aliases through their GUI, then it's easy enough. If you can't find it, you should contact GoDaddy for information.
I was advised to move my answer from here to this question:
While not the same as being able to create a new vhost entry for each subdomain dynamically added, you should be able to set this up using a Wildcard DNS record and adding a dedicated IP to your hosting account. You can add a dedicated IP to your hosting account using this method:
Click Web Hosting.
Click Options, and then click Customize tab.
From the Server IP menu, select Dedicated.
If you already purchased a dedicated IP address credit, click Apply Dedicated IP Credit. OR If you need a dedicated IP address credit, click Checkout, and then complete your purchase.
NOTE: Dedicated IPs can take 24 hours to become active on your hosting account.
You can setup *.yourdomain.com to use the dedicated IP of your shared hosting account in our DNS Manager.
Go to the Zone File Editor for the domain name you want to update.
Click Add New Record. The Add DNS Record window displays.
From the Record type list, select A (Host).
Complete the following fields: Host Name — Enter * Points to IP Address — Enter the Dedicated IP address of your hosting account. TTL — Select how long the server should cache the information.
Click OK.
Click Save Zone File, and then click OK. The new A record displays in the A (Host) section.
I just got off the phone with GoDaddy tech support, and was given a brilliant solution that doesn't require using mod_rewrite or upgrading to a dedicated server.
From your account login at https://gateway.godaddy.com select Hosting from the dropdown and then on the page that opens, select Settings. In the modal window that opens, click the Change Domain button and enter in a dummy domain (note the dummy domain does not need to be registered or entered in DNS. This will then change your default domain to the dummy domain which will reside in the public_html folder.
After you have done that, go to the cPanel and choose Addon Domains from the green menu bar at the top. Enter a new domain and type the name of your registered domain, then specify the document root (DocRoot). The path can be a directory location completely outside of the public_html folder so you can create a Laravel friendly path such as webroot/mydomain.com/public and install Laravel in webroot/mydomain.com.
Likewise, you can specify similar paths for subdomains.
Hope this helps everyone looking at this.

Categories