If I have multiple domain entry points and want to use the same hosting, can I detect by way of PHP or JavaScript what domain that person came though to the hosting website?
ie: I have 3 domains:
www.jackfrost.com
www.holycow.com
www.ohmy.com
Hosting is under www.jackfrost.com.
So if somebody comes in through www.ohmy.com, can I detect that, so I only display content for that entry and different content for a different entry?
(purpose is to keep costs down since the websites are hosted by godaddy)
The best way you can do is to have a look at $_SERVER['HTTP_HOST'] in your PHP script and dispatch your content based on that.
In JavaScript, you can check window.location.hostname for the domain name used.
However, a better way would be to have three different virtual hosts in your webserver configuration - one for each domain you have. This way, even without PHP or any other scripting language, you can have different content for different domains. When using Apache as webserver, you can have a look at the documentation with examples: http://httpd.apache.org/docs/2.2/vhosts/examples.html.
If you do not want or can use name based virtual hosting, you can use only one virtual host, and use mod_rewrite of Apache to internally rewrite requests to other directories based on HTTP_HOST.
If you are using Apache you should set up name-based virtual hosts.
Apache V1
http://httpd.apache.org/docs/1.3/vhosts/name-based.html
Apache V2
http://httpd.apache.org/docs/2.0/vhosts/
Related
I have a site say abc.com and a user account is accessed at abc.com/user. Now I want to add functionality that user can link his site say user.com to abc.com/user. Can u please give me an overview that how this process can be done dynamically via php?
Set up DNS to point the host name at the server
Set up the server configuration so the site is the default virtual host (so if an unrecognised domain name is used to request it, the right site will be loaded)
Use $_SERVER['HTTP_HOST'] instead of the path.
If I understood correctly - you want that a person who is entering user.com will see the content from abc.com/user.
I would recommend checking out launchrock.com they do exactly this, and it involves adding a CNAME dns record as I remember, another way to do this is to create a Proxy flag rule in httpd (mod_proxy must be enabled for this), so that you won't have to restart the server, you can always the .htaccess in your www dir.
doing so dynamically will be easy if you go the proxy route, as you just need to append a new proxypass every time a new site is deployed, or create a parameterized rule, like a regular htaccess, as far as automating DNS records creation, I'm sure that's possible and maybe DNS provider such as godaddy or AWS have api for those kinds of things, but more research is required.
I need a big big help from you guys.
I have a website, say for an example www.abc.com. My Client need to change this entire website for three subdomains to address three countries.all three should be identical copies.
Example:
http://us.abc.com
http://in.abc.com
All the three subdomains should work like the main website.
I thought to copy all my site folders to copy into three folders as US, IN, FR and uploading it into the host and direct those folders to subdomains. Since this will create large number of files and folders I'll hesitate to do this.
Is this method is good or how should I overcome the situation... Glad if you can give me a clue. Thanks.
I'm not entirely sure what your question is:
It sounds like you want to use Apache virtual hosts (so the different domain names will be handled by the same server):
http://www.thegeekstuff.com/2011/07/apache-virtual-host/
Of course, you need to have DNS for the three domains point to your web server
You can use Apache configuration to allow the content to be shared or distinguished between the different domains as you wish.
'Hope that helps...
PS:
To answer your original question:
If "http://us.abc.com" and "http://in.abc.com" were different domains with identical content, you wouldn't even need virtual hosts: you could have "abc.com" serve both. But virtual hosts would still be cleaner - in case you wanted to customize one site or the other in the future.
If, on the other hand, you had "http://mysite.abc.com" and "http://mysite.abc.com.in", then you could still serve both sites from the same server. But you must use virtual hosts (because "abc.com" and "abc.com.in" are different domains).
Again - I hope that helps.
Am sure there's answer on Google but I don't know how to formulate my question:
A php website is hosted on server like this: http://sub.realserver.com/website/index.php
Now I want to link the real domain name to it: http://therealwebsite.com
Problem is, when user visits:http://therealwebsite.com, he will see http://sub.realserver.com/website/index.php as he browse through other pages.
Question is how do I hide this realserver path and replace it with the domain name?
Thanks
edit: the website is hosted on a different server as the real domain name
I presume the domain name and the web site are pointing to the same server.
Although you could use URL rewriting (works with almost all popular web servers), the better solution is to set up your web server to provide that web site for the root of that domain name. How to do that completely depends on what server software you are using.
In apache, you need to create a so-called Virtual Host, configure it to respond to your domain name and set its DocumentRoot directive to the directory where your site is located.
See http://httpd.apache.org/docs/2.0/vhosts/examples.html for an example.
EDIT: I just read your comment. I'm afraid your options are rather limited. The easiest solution, but also the most dirty one, is to create one page with an IFRAME on it, that loads the site from the real server. You could also host a PHP proxy and on the server that hosts your domain name, and let it proxy the site on your
http://sourceforge.net/projects/php-proxy/
(I never used this, nor am I affiliated with this project, but it seems to claim to do what you want.)
I highly recommend though that you update your DNS records on your domain name so that it points to your server that hosts your site, and that you add a virtual host there.
you can do this with asp, there is a good resource on it here -
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
We have a local web server in our office that we use for some reporting and mundane order processing -- nothing major. I recently added some quick code to add a cookie to certain workstations so the user doesn't have log in all the time. The problem I am running in to is that since the server itself acts as an additional workstation, people can access it from http://127.0.0.1, http://localhost or http://192.168.1.111. This ends up creating three distinct cookie domains. Is there any way to configure the server to force one or the other? Or is my only option to move all bookmarks to point to the actual IP address and warn people not to use 127.0.0.1/localhost?
The server is running Apache 2.2 on Windows.
You could check the $_SERVER['HTTP_HOST'] and redirect the browser if a visitor hasn't gone in via the correct hostname.
if('servername' != $_SERVER['HTTP_HOST']) {
Location('http://servername/');
}
If you're running an internal DNS server, you can configure a host/domain name for the server without having to register it - since it's for internal use only, you don't need to expose the name to the rest of the world.
Even without a DNS server, you can add an entry to each machine's hosts file to do the name->ip mapping.
Configure your site to use that name, tell everyone to use that instead, and then the cookies will take care of themselves, since they'll all be set using that host/domain name. You can then add vhosts for the IP-only hits and redirect them to the new named address.
Typically cookies are set to domain names, not ip address. When using a domain name you can use a wildcard setting
.apple.com
Then any variation of that domain will accept the cookies.
I need to direct multiple domains to a single set of (PHP) files. So I point a domain at my server, which then goes to a single index.php file. This index.php file then detects the domain accessing it and returns the appropriate content. I do not want to add domains or set-up sites manually though as this is for a content management service. So it should be a case of a user signing up and it immediately works without me having to manually do anything. The file set must also exist only once, so updates can easily be applied to everyone.
I am currently on shared hosting, but I believe I may need to move to a VPS (running Apache) to achieve this.
How do I go about doing this?
Thanks
Unless I'm missing something about what you're trying to do, a simple CNAME DNS record may work. Just CNAME the new domain to your existing 'main' domain.
However, if you need to know what domain was requested using shared hosting this very well may not work. The catch is you would also have to setup the hosting account to accept requests from the new domain. This seems to be what you're trying to avoid.
If this is the case, you'll need a static IP, and Apache setup to accept wildcard domains and pass them to your application (index.php in this case). You may not need a VPS for this, just a relatively configurable shared hosting account.
Update: To get this working on shared hosting, check out the Apache VirtualHost directive. That's what Apache uses to setup a (wait for it) 'virtual' web server (document root, logs, etc) allowing a single server to host multiple sites. Also checkout Named Based Virtual Hosting, you'll need an account that doesn't do virtual hosting that way.
"So it should be a case of a user signing up and it immediately works without me having to manually do anything"... So you want magic. Anyways domains point to a directory so that is easy just point all domains to the same directory. PHP can examine the full URL so you can use that to select the content.
If you are using something like Joomla you might be able to customize the starting extension. For example all joomla content is stored in tables named jos_XXX.
It should theoretically be modifyable to the base table is domain_com_XXX
Maybe, but you really need to find a good programmer for this, I don't know of any systems that will do this out of the box. Maybe someone else might know of one.