Redirecting non-www to www revisited
-
I′m using WordPress Multisite with subdomains and the WordPress MU Domain Mapping plugin.
My main site′s URL is listed as
https://mainsite.com
(it was suggested by WP to leave out the www during the installation).At the moment my site and all mapped sites are redirected from:
www.domain.com
todomain.com
I′d like to have it the other way around:
domain.com
towww.domain.com
I′ve found various solutions (listed below), each of them working at a different level: DNS, .htaccess, WP database or domain mapping.
I hope someone can explain at which level this redirect should take place so I can find the right solution.
The options I found:
- Redirect the non-www URL to the www using .htaccess
# Redirect to www. RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
(This causes an infinate loop as WP then redircets the www to non-www)
- Define a new constant in the wp-config file including the www:
define(‘WP_SITEURL’,’https://www.mainsite.com’);
- Use the Domain mapping plugin: add a new entry https://www.mainsite.com, with the same Site ID as the mainsite.com entry.
- Add a new CNAME record to your DNS, pointing www to your main domain
Many thanks!
- Redirect the non-www URL to the www using .htaccess
- The topic ‘Redirecting non-www to www revisited’ is closed to new replies.