• Resolved MattV

    (@mattv)


    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:

      define(‘WP_SITEURL’,’http://www.mainsite.com’);

    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!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    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?

    Thread Starter MattV

    (@mattv)

    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?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    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.

    Thread Starter MattV

    (@mattv)

    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!)

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    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.

    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.

    Thread Starter MattV

    (@mattv)

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

    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

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    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.

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

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Redirecting non-www to www revisited’ is closed to new replies.