WordPress.org

Ready to get started?Download WordPress

Forums

Do I need a www to non-www redirection code with WP 3.5? (3 posts)

  1. definitio
    Member
    Posted 1 year ago #

    I have recently migrated my Joomla site to WP and I am wondering whether the www to non-www redirection code I was using is actually needed anymore.
    I have observed that the www. pages are redirected to non-www by default

    However, while before - in Joomla days - Google Webmasters tools reported no issue with the www. version of the site, now I am getting errors that it's not properly indexed.
    So I am worried that whatever redirection WordPress is doing may not be that effective on the whole

    SO I have just added back the redirect code

    ########## Begin - Redirect www to non-www
    ## WARNING: Comment out the non-www to www rule if you choose to use this
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    ## If the above throws an HTTP 500 error, swap [R=301,L] with [R,L]
    ########## End - Redirect non-www to www

    While I had been using this code without trouble, some others were suggesting the following as more appropriate

    RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]

    What is actually the case?
    - Do I need a www. to non-www code in WordPress 3.5?
    - If I do, which of the above is the recommended one?

    Cheers

  2. definitio
    Member
    Posted 1 year ago #

    Sorry, I posted the non-www to www code in the last instance above.

  3. definitio
    Member
    Posted 1 year ago #

    bumping this up...

    1) Should I be using an htaccess rewrite rule to point http://www.mysite.com/* to mysite.com/* given that WP does that in some way?

    2) What's the best way to do that?
    I have come across various suggested codes

    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    or

    RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]

    or

    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    or

    RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com [NC]
    RewriteRule ^(.*)$ http://%1.example.com/$1 [R=301,L]

    or

    RewriteCond %{HTTP_HOST} ^www.example.com [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

    What do WP knowledgeable users recommend?

Topic Closed

This topic has been closed to new replies.

About this Topic