Support » Fixing WordPress » Require “www.” : Troubleshooting & Question

  • Resolved saphod

    (@saphod)


    I recently read that it is better for search engines to either ALWAYS or NEVER have “www.” in your blog URIs, but not both.

    My WP General Options were set to “http://www.saphod.net”.

    Well, I thought >>Give the “www.” a chance<< and included the following rules in my .htaccess-file right below RewriteBase:

    # Require "www."
    RewriteCond %{HTTP_HOST} !^www\.saphod\.(net|com|de)$ [NC]
    RewriteRule ^(.*)$ http://www.saphod.net/$1 [R=301,L]

    Works fine.

    But I noticed that even before, a URI without “www.” was already automatically redirected.

    According to the WordPress Codex, the blog URI should be without “www.”. So, as a test, I changed it to http://saphod.net.

    Result:
    I got a redirection loop every time I typed in e.g. saphod.net!

    Here is what I suppose:
    WP already redirects to the URI provided in the options, meaning that it already strips or adds “www.”. Is that right?

    Therefore, the RewriteRule tries to make saphod.net –> http://www.saphod.net, then comes WordPress and changes http://www.saphod.net –> saphod.net and then the .htaccess RewriteRule comes again and the same thing happens over and over and over again.

    Question:
    If I am right and WP already redirects, I could leave the RewriteRule out of my .htaccess, right?

    A short note on this would be nice.
    Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • yes, that’s right… wp already redirects, so you don’t need the rewrite rule.

    As for the codex suggesting that the URI should not include the www, that’s largely due to personal preference and the difference between one or the other is negligible, as long as you pick one and stick to it.

    Some people prefer to write their addresses as mysite.com, others feel that http://www.mysite.com reduces the need to use the http protocol prefix.

    Personally, I don’t care, but I will note that even the auto-linking algorithm here will convert sites either with http:// or www. but will not recognise sites without a leading prefix, suggesting that if you want your links to be machine-readable, you should include a prefix…. and if you’re including a prefix, then certainly the Ws are far easier to type all the time, right?

    Anyhow, if they both work when typing the URL into your address bar, but only one remains there to be copied/pasted into people’s links, then you’re all good.

    Thread Starter saphod

    (@saphod)

    and if you’re including a prefix, then certainly the Ws are far easier to type all the time, right?

    Absolutely!
    Thanks for the quick answer.

    Thread Starter saphod

    (@saphod)

    Oh, another quick question:

    As I am very interested in the technical aspects of WP:
    Where exactly is this redirection located in WordPress (function, class, file…)?

    No idea, personally – I’ve never had occasion to look for it.
    I’m sure you’ve found it by now anyway.

    Thread Starter saphod

    (@saphod)

    Not yet, but I will be patiently waiting for a WP pro to show me… 🙂

    I believe this function is in wp-includes/canonical.php 🙂

    Thread Starter saphod

    (@saphod)

    Yip, so it seems. Thanks! 🙂

    No problem. 🙂

    One caution is that this is a WordPress core file, so it may be overwritten upon upgrade.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Note, not having www is the preferred way to do things.

    The www prefix is deprecated.

    So how should I do it if I want to have a www prefix in front of my website?

    Since the rewrite code will always be in a loop …

    Thread Starter saphod

    (@saphod)

    @seedpxwee5:
    No Rewrite in .htaccess needed.

    Put the “www.” in front of the blog location in General Options – so, instead of “http://yourdom.ain&#8221;, it should read “http://www.yourdom.ain&#8221;.

    As can be read here, WP then automatically redirects “yourdom.ain” requests to “www.yourdom.ain”…

    But I have no idea what the effect on search engine rankings is, since each of your blog posts should be without the “www.” so far.

    You should have the remark made by Otto42 in the back of your head. For new blogs, I would not add the “www.” any more.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Require “www.” : Troubleshooting & Question’ is closed to new replies.