Mobile app version of vmapp.org
Login or Join
Sent6035632

: Redirect various http domains to certain https domain via htaccess I have a bunch of domain names with different TLDs. What I want is to point several domains to the "main"-domain which has

@Sent6035632

Posted in: #Htaccess #Https #Redirects #UrlRewriting

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:
maindomain.com (main domain with SSL cert) additionaldomain1.net (should redirect to maincomain.com and rewrite the URLs) additionaldomain2.org (should redirect to 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 maindomain.com and rewrites the URLs correctly.

I tried the simplest thing that came to my mind:

Redirect permanent / maindomain.com/

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

Edit:

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

Can someone please help?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Sent6035632

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

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 (.*) maindomain.com/ [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 (.*) maindomain.com/ [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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme