Lets say for example my website address is: www.example.com
I let my users each have a website at user1.example.com, user2.example.com - I have achieved this through wildcard sub domains etc.
How can I let my users have these sites (which I host) at specialpage.theirsite.com? They would add a cname record for specialpage pointing to userpages.example.com - How would I handle hosting these pages once they have been pointed? Preferably in PHP!
The best solution is to use CloudFlare wildcard DNS entries to point all unset subdomains to the A record for userpages.example.com and then use a php script in the directory for userpages.example.com to check if the subdomain has been setup.
<?php
$subdomain = array_shift((explode(".",$_SERVER['HTTP_HOST'])));
if ($subdomain IN DATABASE) echo DATABASEOUTPUT;
else echo 'Domain: "' . $subdomain . '.example.com"';
?>
Related
I am coding on a social site in CakePHP say example.com, here in the users profiles are located at example.com/profiles/user1. Now I need to provide the functionality to the users to use their custom domains for profiles. For example user1.com should render content from example.com/profiles/user1
Please suggest me the best solution for my problem. I am working on Shared Hosting - Linux Server.
For this functionality, you need to point user1.com to example.com/profiles/user1
For this I can think of two methods:
1. Name server Method:
you can change name servers of user1.com to your example.com name servers like:
ns1.example.com
ns2.example.com
NOTE: This may take 3-4 hours to work
2. URL Forwarding Method:
You can also use URL forwarding to point user1.com to example.com .
This will give you basic idea of forwarding http://support.godaddy.com/help/article/422/forwarding-or-masking-your-domain-name
Assuming that you both have a wildcard record in DNS and that the webserver is configured to serve your Cake project from those hostnames (how to do these things will depend upon your hosting provider), then (with thanks to Subdomaining with Cake), you simply need to place the following in app/config/bootstrap.php:
$subdomain = substr( env('HTTP_HOST'), 0, strpos(env('HTTP_HOST'), '.') );
if( strlen($subdomain)>0 && $subdomain != 'www' ) {
$_GET['url'] = 'user/' . $subdomain . '/' . (isset($_GET['url']) ? $_GET['url'] : '');
}
I am working on an php website,
my website url is something like
http://www.xyz.com/hosted/abc.com
I want to access the pages with above url with a cname like http://abc.xyz.com
Means if i type http://abc.xyz.com as url it should internally serve me the pages for http://www.xyz.com/hosted/abc.com.
Please suggest,if anyone know how to achieve this ?Thanks in advance.
If you use bind for dns server you must make a DNS zone manually and add an A record *.xyz.com. into this zone to redirect all the hosts like *.xyz.com to your web server.
Or if you use cPanel go to Simple DNS Zone Editor add an A Record with this name : *.xyz.com. and set Address your server's IP address.
If you use another Control Panel or DNS Server Service you have to read manual to handle requests for *.xyz.com
Then in your php code you can get the requested cname :
$host = $_SERVER['HTTP_HOST'];
$match = preg_match("([a-zA-Z0-9\-])\.xyz\.com");
$cname = $match[0];
I want to check the Referrer url is Main Domain or Sub domain, domain can be anything like .com , .net ,.co.in , in .. Sub Domain also can be different type… any one can suggest idea in PHP script …..
For e.g if referrer url is http://google.com is the Domain, http://in.google.net is the sub domain
This should do the trick. (Haven't tested the code - so please take as a suggestion only)
<?php
$fromOtherDomain = !preg_match('/^https?:\/\/' . preg_quote($_SERVER['HTTP_HOST']) . '/i', $_SERVER['HTTP_REFERRER']);
?>
I got the Answer.
The requirement has changed and I now match all subdomains belonging to same domain (*.example.com).
So I have used the following code:
if(!preg_match('/[A-Za-z0-9].example.com/', $_SERVER['HTTP_REFERER'])){
echo 'Sub Domain';
}else{
echo 'Main domain OR sub domain not belongs to example.com'
}
I am on shared hosting and on a add on domain.
I need to create subdomain for each user of my website like if the username is jeff then he should have a url jeff.mydomain.com.
How can I create it programmatically using PHP?
There's two parts to this. Firstly you'll need to setup a wildcard dns entry.
Once you've got that setup you should have all your requests pointed back to a single domain. From there you can then use php to figure out which domain you're currently on:
$domain = $_SERVER['HTTP_HOST'];
$base = 'mydomain.com';
$user = substr($domain, 0, -(strlen($base)+1));// the user part of the domain
if(!empty($user)) {
$user = sanatiseUser($user);
require_once $user.'.php';
}
You need to set apache to listen for all domains coming into a specific IP.
You then need to setup a wildcard DNS entry to point *.domain.com to that IP.
Then inside your app, use $_SERVER['HTTP_HOST'] to determine which user to load.
I have a main domain name associated with a WordPress site, and then I have a couple other domain names connected to that site as well.
I want the other two domains names to point/redirect to specific pages on the site rather than the index page, which is the default.
So when domain1.com is typed into the browser, it goes to maindomain.com/domain1page/ (this is how the permalinks are set up). Is this possible?
Add this to index.php and upload it the root of domain1.com
<?php
header("location:http://maindomain.com/domain1page/");
?>
OR if you do not have a Hosting package for domain1.com go to the Domain Manager and in Nameservers you can enter a URL to redirect your domain to there.
It's possible, but you must add each domain manually. Just redirect them to your page.
Sure - there are lots of different ways to do this. Some registrars let you set up redirects at the domain level. You could also have a website set up for each domain on your server, and then just redirect to the page you'd like from that. You could also use the httpd.ini file to detect the domain and redirect to the appropriate page.
This is a small script that might serve the purpose.
You should place this at the top of header.php in your wordpress theme.
The script will not do anything if a domain is not matched so wordpress will load normal page. Haven't tested, but it should work.
<?php
$host = $_SERVER["HTTP_HOST"];
//Setup Domains Directory Names Here
$domain1 = 'domainname1.com';
$domain1_dir = 'domain1directoryhere';
$domain2 = 'domainname2.com';
$domain2_dir = 'domain2directoryhere';
$domain3 = 'domainname3.com';
$domain3_dir = 'domain3directoryhere';
//Redirects to directory depending domain.
switch (true){
case (preg_match("/$domain1/",$host)):
header("location:/$domain1_dir");
break;
case (preg_match("/$domain2/",$host)):
header("location:/$domain2_dir");
break;
case (preg_match("/$domain3/",$host)):
header("location:/$domain3_dir");
break;
}
?>