Knowledge base

1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!

Force a domain name in the URL displayed by the web browser

Update 08/11/2026

This guide explains how to redirect traffic from an alias (synonym) domain name to your main domain, or force the display of the main domain in the browser's address bar.

 

Prevent duplicate content

Let's imagine that your website is hosted under the main domain example.com and that you have configured an alias domain such as example-alias.com.

By default, when a visitor enters one or the other of these addresses in their browser, the typed URL remains displayed. This can generate duplicate content, which harms natural search engine optimization (SEO).

To prevent this, you can force a redirect: if a visitor types example-alias.com, they will be automatically redirected to example.com.

This configuration is done in the .htaccess file located at the root of your hosting (usually in the /web folder via your FTP access). If this file does not yet exist, you must create it.

Then, insert the following directives into the file:

RewriteEngine On

# Force HTTPS and canonical domain redirection
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

Adapt the code above to your needs:

  • Replace example.com with your main domain name and its extension (.com, .org, .ch, etc.). Add www. before your domain if you prefer to force the display of the www subdomain.
  • If a redirection loop occurs, you can replace the protocol condition with RewriteCond %{HTTPS} off (especially if your hosting does not use a reverse proxy).

For more information, see the documentation on automatic redirects to HTTPS.


Has this FAQ been helpful?