6

I have a bunch of domain names with different TLDs. What I want is to point several domains to the "main"-domain which has a SSL cert (single domain).

Like this:

https://maindomain.com (main domain with SSL cert)
http://additionaldomain1.net (should redirect to https://maincomain.com and rewrite the URLs)
http://additionaldomain2.org (should redirect to https://maincomain.com and rewrite the URLs)

The https domain points to the directory which contains the website data. I created a subfolder in that directory where I pointed the additional domains to, because I was thinking I could place a htaccess file there to manage redirection and rewriting. Is that OK so far?

I am having trouble finding the correct htaccess rules which permanently redirect the requested domain (either additionaldomain1.net or additionaldomain2.org) to https://maindomain.com and rewrites the URLs correctly.

I tried the simplest thing that came to my mind:

Redirect permanent / https://maindomain.com/

But that resulted in e.g. https://additionaldomain1.net which, of course, does not work.

Edit:

I use WordPress and put https://maindomain.com as blog URL as well as site URL in the settings and I made WordPress force SSL.

Can someone please help?

  • "I tried the simplest thing" - presumably this was in the .htaccess file in the subdirectory? That redirect could not result in the redirect as stated, so it's likely conflicting with the .htaccess file in the parent directory. Just to clarify, http://additionaldomain is not accessible over HTTPS? (You didn't need to use subdirectories if you simply wanted to redirect, you could just point these additional domains to the document root of the main domain.) – MrWhite Sep 7 '15 at 12:00
  • Yes, conflicting htaccess's would be my guess too. Both additional domains are not accessible via HTTPS since I only have a single domain SSL cert... which I used for the main domain. I surely could just point the additional domains to the correct directory but wouldn't that mean a user could also access the site via HTTP and wouldn't that result in duplicate content? I'm asking because I need every user to access the site via HTTPS. – okiedokey Sep 7 '15 at 12:19
  • Even if the additional domains point to the document root, you would still implement the same redirects. Except you wouldn't need the additional subdirectory and .htaccess file. I'll add an answer for your current setup... – MrWhite Sep 7 '15 at 12:26
3

With your additional domains pointing to subdirectories off the main domain's document root, you can add the following to the .htaccess in that subdirectory to redirect to the main domain:

RewriteEngine On
RewriteRule (.*) https://maindomain.com/$1 [R=302,L]

Note that this uses mod_rewrite, not mod_alias (Redirect). As such it will override the mod_rewrite directives in the parent .htaccess file. This assumes that the parent .htaccess file (which includes the WordPress directives) does not use mod_alias. (WordPress usually only uses mod_rewrite.)

Change the 302 (temporary) redirect to a 301 (permanent) redirect when you are happy it's working OK.


An alternative (as mentioned in comments) is to simply point these additional domains to the main domain's document root as opposed to subdirectories. Then, you would need to modify the main domains .htaccess file and include a similar external redirect before the WordPress directives. Something like:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?additionaldomain1\.net$
RewriteRule (.*) https://maindomain.com/$1 [R=302,L]

In fact, you could do this anyway with the subdirectories, and not use the .htaccess file in the subdirectory. .htaccess files are inherited by default.

  • Thank you, very comprehensive! I used the second way you described because it actually makes more sense. But I'm facing the problem that in Firefox, the URL is https://additionaldomain1.net (which doesn't work and throws an error). In Chrome I'm being redirected, but the URL does not change to https://maindomain.com and my iconfont does not display unless I use the page navigation to open another site else than front page. Can you imagine why? – okiedokey Sep 7 '15 at 13:00
  • Trying clearing your browser cache (particularly if you are seeing different results in different browsers). If you had previously tested with 301/permanent redirects then these (incorrect redirects) will have been cached by the browser (which is why it's often preferable to test with 302/temporary redirects). "In Chrome I'm being redirected" - where are you being redirected to, if it's not https://maindomain.com? You might need to add the contents of your .htaccess file to your question so we can check for any conflicts. – MrWhite Sep 7 '15 at 13:58
  • Duh, pleace excuse my last comment because I'm an idiot. First thing is of course I hadn't thought of the cache. Second, I did not realize my changes to my htaccess file weren't made because FileZilla couldn't reupload the file. I still went with your second advice and it works.... of course! – okiedokey Sep 7 '15 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.