Knowledge base
1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!
Add a site to a hosting by subdomain and .htaccess
This guide explains how to create subdomains on an existing Infomaniak hosting using a .htaccess file.
Introduction
- The hosting can be on an offer of Shared Web Hosting or on Infomaniak Cloud Server but this function is impossible with a Starter hosting.
- Subdomains can be added very easily to your current hosting since you have in the basic offer 20 sites per hosting (sites = subdomains).
- If you do not want to use this site volume available to you, you can follow the method below.
Create a subdomain as a shortcut
The subdomains thus created make it easier to organize a hosting. For example the address vlog.domain.xyz will be the shortcut of the address domain.xyz/vlog. In other words, the address vlog.domain.xyz will redirect to the vlog folder 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 of your website
To do this:
- Follow the procedure for adding an alias but please read the points 2 and 3 below.
- In the field to add the related domain, enter the full address of the subdomain (for example
vlog.domain.xyz). - If your domain or its DNS zone is managed at Infomaniak, activate the following two options: Update DNS entries for this domain and Replace existing entries ; if this is not the case, create a A record with your registrar with the following information:
- field: the full URL of the subdomain (for example
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 of the subdomain (for example
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 work in your situation.
Using your FTP software/client or Web FTP on the 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:
domainwith your domain namexyzwith your domain extension (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 exists at the root of your website.
Link to this FAQ:
Has this FAQ been helpful?