Forums

[resolved] Require "www." : Troubleshooting & Question (12 posts)

  1. saphod
    Member
    Posted 4 years ago #

    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!

  2. Ivovic
    Member
    Posted 4 years ago #

    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.

  3. saphod
    Member
    Posted 4 years ago #

    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.

  4. saphod
    Member
    Posted 4 years ago #

    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...)?

  5. Ivovic
    Member
    Posted 4 years ago #

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

  6. saphod
    Member
    Posted 4 years ago #

    Not yet, but I will be patiently waiting for a WP pro to show me... :-)

  7. Eric Amundson
    Member
    Posted 4 years ago #

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

  8. saphod
    Member
    Posted 4 years ago #

    Yip, so it seems. Thanks! :-)

  9. Eric Amundson
    Member
    Posted 3 years ago #

    No problem. :)

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

  10. Otto
    Tech Ninja
    Posted 3 years ago #

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

    The www prefix is deprecated.

  11. seedpxwee5
    Member
    Posted 3 years ago #

    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 ...

  12. saphod
    Member
    Posted 3 years ago #

    @seedpxwee5:
    No Rewrite in .htaccess needed.

    Put the "www." in front of the blog location in General Options - so, instead of "http://yourdom.ain", it should read "http://www.yourdom.ain".

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic