Forum Moderators: phranque
Is there a way to truly point the domain name to the hosting folder without forwarding the domain?
Thanks.
You register your domain name through a registrar, set it to the same dns addresses as your primary domain, then log into your cpanel and go through the add-on domain process to tell it the new domain name. Supposing your domain was otherexample.com, you'd then place that site's files in public_html/otherexample.
If you have some other control interface than cpanel it may use different terminology but will likely work in a very similar fashion - your host may have a FAQ page buried somewhere that tells you how to do it.
Create folders inside that one, one for each site, and then each website will go in a separate folder.
In the Control Panel, you associate one domain name with one folder.
There will be a domain name associated with the root folder. In that case, I usually don't put up a site for that domain name, or else I set up a rewite to actually pull content from one particular folder.
Having set things up, there is a flaw.
Each site will be accessible, as examplemaindomain.com/subsitename and as examplewhatever.com and as www.examplewhatever.com which is a problem.
Next, you would add rules to your root .htaccess file such that if anyone asks for examplemaindomain.com/subsitename then they are redirected to www.examplewhatever.com .
In the folder itself, you would make sure that the .htaccess file in there redirected requests for examplewhatever.com over to www.examplewhatever.com.
Those redirects would be "site-wide" per domain, and must return a 301 response code in the HTTP header.
That's it.
You could put your first site in there, but the view when you FTP in becomes cluttered. Therefore I often leave that folder blank, and rewrite to a sub-folder for the main site.
That is what I have done on a few occasions.
Sometimes I pointed one of the .info or .biz or somesuch domains there. The .htaccess in the root then deals with the folder redirects as before, as well as the redirect to the canonical .com where that site really resides (with its' files being in one of the folders of course).
Redirect all non-www and www requests for examplemainsite.com/foldersite
that are requesting named index files to redirect to www.example.com
preserving the folder path, stripping the index filename off, and forcing
the www on. Redirect all non-www and www requests for examplemainsite.com/foldersite
for all other paths and files to redirect to www.example.com preserving
the folder and file path, and forcing the www on. You'll need to repeat that code in the base .htaccess for each separate site that exists, where that site is hosted within a folder of this domain.
If any of those sites use URL rewriting, you'll also need:
a set of rules here (one set for each site) to redirect requests for
parameter-based URLs within examplemainsite.com/foldersite (both www
and non-www) to be redirected to folder-based URLs at www.example.com
and to force the www at the same time. Those redirects would be placed
before the others listed above. .
In each folder, where a single domain resolves to, you will need this in each .htaccess file within the individual folder:
Redirects to fix up malformed requests (multiple // in request, comma
instead of period, trailing spurious punctuation, etc.) and force the
www on to www.example.com at the same time for those. Redirect for both www and non-www to strip index filenames and force
the www on to the URL at www.example.com too. Redirect from non-www to www, site-wide, and which preserves the
requested filepath, ending up at www.example.com. If you also use URL rewriting you'll also need:
a set of rules to redirect requests for parameter-based URLs (both www
and non-www) to be redirected to folder-based URLs at www.example.com
(forcing the www at the same time). Those redirects would be placed
before the others listed above. Finally, you would have your rewrites to internal filepaths. .
To miss any of those steps would leave the sites open to being indexed under alternative (duplicate) URLs and/or domains.
Suddenly the job is a lot more complex than just a couple of redirects...
- not delegating domain at all ( at least after initial setup )
- password protecting root directory of domain
- robot.txt exclude
- rewrite anything on domain to /index.html
Am I correct in assuming all/most of steps you outline are also apply if you have a real site on the root folder.
Thanks again.