Laravel Forge multiple top level domains (TLD) redirect to one site with SSL

Viewed 790

Has someone managed to set up multiple top level domains for one site on Laravel Forge, with SSL for each domain. Additionally all domains should redirect to one main domain.

e.g.

main domain: themaindomain.com

other domains should be redirected to https://themaindomain.com

http://example.com -> https://themaindomain.com

http://www.example.com -> https://themaindomain.com

https://example.com -> https://themaindomain.com

https://www.example.com -> https://themaindomain.com

I just set it up like this blog post: https://blog.laravel.com/forge-alias-domains but now when i go to http://www.example.com it just redirects to https://example.com, but it should redirect to https://themaindomain.com/ to avoid duplicate content.

I have added a Let's Encrypt through Laravel Forge where I added all domains in one request:

themaindomain.com,www.themaindomain.com,example.com,www.example.com

That worked as expected, only thing missing is the correct redirect

1 Answers

As far as I can tell the only way to do this without manually altering the nginx config is by creating a separate site for example.org (which also covers www.example.org) and then add a redirect at the app level with the following settings:

From: /
To: https://themaindomain.com
Type: Permanent # optionally: start with temporary to make sure it works

enter image description here

Related