1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Add a site to hosting by subdomain and .htaccess
This guide explains how to create subdomains on an existing Infomaniak hosting, using a .htaccess
file.
Preamble
- The hosting can be on a Shared Web Hosting offer or on a Cloud Server but this function is impossible with a Starter hosting.
- Subdomains can be added very easily to your current hosting since you have 20 sites per hosting (sites = subdomains) included in the base offer.
- If you do not wish to use this available site volume, you can follow the method below.
Create a subdomain as a shortcut
The subdomains created in this way help to organize a hosting. For example, the address vlog.domain.xyz
will be a shortcut for the address domain.xyz/vlog
. In other words, the address vlog.domain.xyz
will redirect to the folder vlog
which must be located at the root of the website domain.xyz
. In this example, vlog
is the subdomain of domain.xyz
.
1. Add the subdomain as an alias for your website
To do this:
- Follow the alias addition procedure but please read points 2 and 3 below.
- In the field to add the linked domain, enter the full address of the subdomain (e.g.
vlog.domain.xyz
). - If your domain or its DNS zone is managed by Infomaniak, enable the following two options: Update the DNS records for this domain and Replace existing entries ; if that is not the case, create a A record with your registrar with the following information:
- field: the full URL address of the subdomain (e.g.
vlog.domain.xyz
) - target: the IPv4 address (A record) of your site (refer to this other guide to find the A record of your site)
- field: the full URL address of the subdomain (e.g.
2. Modify the .htaccess file of your website
Important: the following instructions are given for informational purposes only. You may need to adapt the code to make it work in your situation.
Using your FTP software/client or the FTP Manager, add and adapt the following code in the .htaccess
file located at the root of your website:
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.xyz [NC]
RewriteCond %{DOCUMENT_ROOT}/%1/ -d
RewriteCond %1::%{REQUEST_URI} !^(.*?)::/\1/?
RewriteRule "^(.*)$" "%{DOCUMENT_ROOT}/%1/$1" [L]
Explanation for the third line: https://stackoverflow.com/a/15981056
Replace on the first line:
domain
with your domain namexyz
by the extension of your domain name (ch, fr, etc.)
Now, the address vlog.domain.xyz
should display the content of the vlog
folder located at the root of your website. If this is not the case, check that the vlog
folder actually exists at the root of your website.