wiki:faq/domain/canonical-web-address

Version 9 (modified by JaimeV, 3 years ago) (diff)

--

I have multiple domain names that point to my web site - how to I make it so my preferred domain always appears in the browser address bar?

Many of us have multiple domain names that point to the same web site. For example, you can access our web site by going to mayfirst.org, or www.mayfirst.org, or www.people-link.net, etc.

However, we want people to always see mayfirst.org in the address bar of the browser.

We do that by adding the following lines to the Web Config settings in the Members Control Panel:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.org$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://example.org/$1 [L,R]

You can do the same by replacing example.org with the domain name you want your web site to display in the address bar of the browser. Be sure to place these lines outside of the <Directory> </Directory> section of your web configuration (if it existed), not within it; otherwise, the rewrite rules won't work.

The Apache docs suggest the above should now be done using an If statement and Redirect rule as written below.

<If "req('Host') != 'example.org'">
    Redirect "/" "http://example.org/"
</If>

What if I want to force visitor of my website to use HTTPS?

You can add the following lines to the Web Config settings in the Members Control Panel:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://example.org/$1 [L,R]

The Apache docs suggest the above should now be done using a simpler Redirect rule as written below.

Redirect "/" "https://www.example.org/"