Knowledge base
1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!
Add a website to a hosting account using a subdomain and .htaccess
This guide explains how to create subdomains on an existing Infomaniak hosting account, using an .htaccess file.
✘ NOT AVAILABLE with
Site Creator Lite
hosting plans Starter
Preamble
- Hosting can be provided through a Shared Web Hosting plan or on an Infomaniak Cloud Server.
- Subdomains can be added very easily to your current hosting plan, as the basic plan includes 20 sites per hosting plan (sites = subdomains).
- If you do not wish to use this number of sites, you can follow the method below.
Create a subdomain as a shortcut
Subdomains created in this way make it easier to organize a hosting environment. For example, the address vlog.domain.xyz will be the shortcut for 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 domain.xyz website. 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 procedure for adding an alias, but please read points 2 and 3 below.
- In the field for adding the associated domain, enter the complete address of the subdomain (e.g.
vlog.domain.xyz). - If your domain or its DNS zone is managed with Infomaniak, enable the following two options: Update DNS entries for this domain and Replace existing entries; if this is not the case, create an A record with your registrar using the following information:
- field: the complete URL of the subdomain (e.g.
vlog.domain.xyz) - target: the IPv4 address (A record) of your website (refer to this other guide to find the A record of your website)
- field: the complete URL of the subdomain (e.g.
2. Modify the .htaccess file of your website
Important: The following instructions are provided for guidance only. You may need to adapt the code to make it work in your specific situation.
Using your FTP software/client or Web FTP in the Manager, add and adapt the following code to the .htaccess file located in the root directory 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
On the first line, replace:
domainwith your domain namexyzby extending 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.
Link to this FAQ: https://faq.infomaniak.com/2036
Has this FAQ been helpful?