Htaccess redirect multiple www and non-www sites


#1

Hi

Like many people with new websites, I tend to use https://newwebsite.com

I’d like to redirect (with 301) multiple OLD sites (both www and non-www) to the above site

Eg

www.example1.com
example1.com
www.example2.com
example2.com

All to redirect (301) to the following:

https://newwebsite.com

I have asked for forum support but am a bit confused and I’ve searched high and low for an answer on google!

What clean code would you suggest?
Does this require 4 separate conditions?

Thanks

Richard


#2

Not sure if I understood you thoroughly, but if you add your other domains as additional domains in your app, then Cloudways will set up redirection to your main domain automatically.

Looks like there’s no need to add both www and non-www.

Tested the above with Wordpress, not sure about other platforms. But surely that redirection is not a feature of Wordpress.


#3

Thanks

Re Additional domains, cloudways documents says

‘In this option, any additional domain whether it is a sub-domain e.g. shop.mysite.com or an another domain e.g. mysite2.com/www.mysite2.com for accessing the same website shall be added under Additional Domain option’

Cloudways -
(1) Does this work? In which case add both www and non-www
(2) Why does support not recommend this but htaccess instead? I’ve contacted supported around 3 times over this issue (different domain name changes) and they reply with htaccess.
Does the cloudways add domain do a 301 redirect?

(3) Please provide the htaccess code as well!

Many Thanks

Richard


#4

Cloudways support - much appreciate a response please.