Redirect a domain to subdomain www by default

Last change on 2021-07-07 • Created on 2020-01-20

You can set up a default redirect without the www. prefix to a domain with the www. prefix using the mod_rewrite command.

Set up an .htaccess file with the following content in the root directory (Document Root) of the domain. Then replace "" with your domain name. (Do not remove any backslashes in the code!)

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.your-domain\.de [NC]
RewriteRule (.*)$1 [L]

This redirects all enquiries, with or without www., to the default URL

If you want to point more domains to this folder, simply attach further "Conditions" directly to the code above:

RewriteCond %{HTTP_HOST} !^www\.another-domain\.de [NC]
RewriteRule (.*)$1 [L]

Redirect addon domains to the main domain

Similarly, you can also redirect addon domains to the main domain. This would, for example, let you always display the same URL in the browser's address bar. Example:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?addon-domain\.de [NC]
RewriteRule (.*)$1 [L]

The reverse is also possible. You can also redirect a main domain to an addon domain.

Table of Contents