1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Add a site to hosting via subdomain and htaccess
This guide allows you to create subdomains with web hosting, including Cloud Server. However, this function is not possible with Starter hosting (the 10 MB hosting included with each domain name).
Subdomains make it easier to organize hosting. For example, the address vlog.domain.xyz is a shortcut for the address domain.xyz/vlog. In other words, the address vlog.domain.xyz points to the vlog folder located at the root of the website domain.xyz. In this example, vlog is the subdomain of domain.xyz.
Step 1: Add the Subdomain as an Alias for Your Website
- Follow the alias adding procedure but please read points 2 and 3 below carefully
- In the Alias domain name field, enter the complete subdomain address (e.g., vlog.domain.xyz)
- If your domain or its DNS zone is managed by Infomaniak, enable the following two options: Update DNS entries for this domain and Replace existing entries. If not, create an A record with your registrar with the following information:
- Field: the complete URL of the subdomain (e.g., vlog.domain.xyz)
- Target: the IPv4 address (A record) of your site (how to display your site's A record)
Step 2: Modify the htaccess File of Your Website
Important: The following instructions are provided for reference only. You may need to adapt the code to make it work in your situation.
Using your FTP software or our FTP Manager, add and adapt the following code to 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 name
- xyz with the extension of your domain (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 it doesn't, check if the vlog folder exists at the root of your website.