[resolved] Redirecting non-www to www revisited (11 posts)

  1. MattV
    Posted 4 years ago #

    I´m using WordPress Multisite with subdomains and the WordPress MU Domain Mapping plugin.

    My main site´s URL is listed as http://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 to domain.com

    I´d like to have it the other way around:
    domain.com to www.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:

    1. Redirect the non-www URL to the www using .htaccess
      # Redirect to www.
      RewriteCond %{HTTP_HOST} !^www\.
      RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
      (This causes an infinate loop as WP then redircets the www to non-www)
    2. Define a new constant in the wp-config file including the www:


    3. Use the Domain mapping plugin: add a new entry http://www.mainsite.com, with the same Site ID as the mainsite.com entry.
    4. Add a new CNAME record to your DNS, pointing www to your main domain

    Many thanks!

  2. With MultiSite it's a BIT more complicated, since you have multiple places in the database where the domain is set to domain.com.

    I would strongly recommend leaving it the heck alone if it's working. Why do you want to change it?

  3. MattV
    Posted 4 years ago #

    I´ve moved an exisiting site from a single WP install to WP Multisite. The old URL always had the www included, like: www.domain.com

    For continuity I´d like to keep the same URL structure (with the www inluded I mean).

    If editing the DB is not a good idea, would any of the other options (htaccess/cname) be a "preferred" solution?

  4. Yeah, it's not the same thing, editing single site as multisite with those changes.

    Frankly, the www doesn't matter, so long as your old URLs are seamlessly redirected to the new ones.

    The best way if you REALLY want to do this is to edit your wp-config and THEN go through the database and find every instance of domain.com and add in www. Then go back and look again, cause you may have missed one.

    It's seriously a pain in the ass. Unless you really, truly, have to. Don't. if it's just cause you like www better, I strongly suggest you lean to love sans www :) Any mismatch, any missed file, can cause your site to break. Badly.

  5. MattV
    Posted 4 years ago #

    Ok that´s very clear :)

    So far I´ve this:

    • htaccess: no option, this will cause an infinite redirect loop
    • wp databse: very risky, better not mess with it

    Would the other options be a solution? (Point 3 and 4 in my first post: a new entry in the domain mapping plugin or adding a CNAME record)

    (There are so many questions regarding this topic that I thought it would be good to cover all the options in one single thread. Also for others who´ll have the same question. I really aprictae your help!!
    - Thanks!)

  6. Domain mapping or CNAME MIGHT work, but it also may cause the same problem as htaccess :/ You'll have to test and check, as I've not tried them. I HAVE done the domain, and it's a pain.

  7. Use the Domain mapping plugin: add a new entry http://www.mainsite.com, with the same Site ID as the mainsite.com entry.

    this is the simplest solution. if you're mapping the site already, you can just add the domain again with the www.

  8. MattV
    Posted 4 years ago #

    Thanks Ipstenu & Andrea, it´s very clear now!

  9. ruben86
    Posted 4 years ago #

    Anyone an idea how to fix this for the primary URL?
    Since this is site ID 1, I tried to add http://www.mydomain.com and set it as primary. But the record isn't saved.

    Most important is that my main site shows: http://www.mydomain.com instead of mydomain.com

  10. ruben86 - This topic is marked resolved, which means you need to make your OWN topic for yourself :)

    You can't map the MAIN URL via the domain mapping plugin. You would need to essentially change the URL on your site, and it's a pain in the butt.

  11. ruben86
    Posted 4 years ago #

    Oh, sorry! In that case I leave it as it is... Thanks anyway

Topic Closed

This topic has been closed to new replies.

About this Topic