WordPress.org

Ready to get started?Download WordPress

Forums

301 to non-www (instead of default 302) (5 posts)

  1. Jiglet
    Member
    Posted 5 years ago #

    I realize that a lot of people probably 301 from http://domain.com to http://www.domain.com - I'd like to do the opposite. I have backlinks pointing to both versions of the site, and I'd like to take full advantage of them.

    I'm pretty sure that by default, WP redirects via 302, which is a temporary redirect if I understand correctly. I know that a 301 can be achieved via .htaccess, not exactly sure how (seen it done from non-www to www, but not vice-versa).

    Anyway, I want to know what the best way to do this is, and also curious if this can potentially mess up my WP installation. Any help would be much appreciated. Thanks!

  2. Jiglet
    Member
    Posted 5 years ago #

    Did some research over the weekend and I'm still not sure what the best solution for this is... Does anyone have any idea?

  3. nikc
    Member
    Posted 5 years ago #

    What you're looking for is mod_rewrite. There are plenty of howtos around that will hand the solution to you. Google is your friend here.

    I recommend the Apache reference, if you're already atleast vaguely familiar with mod_rewrite http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

    But basically, this is what you're after (mind you, this is off the top of my head and untested):

    RewriteEngine on # Turns on the RewriteEngine
    RewriteCond %{HOST} ^www\.host\.com$ # Match to your domain with www-host
    RewriteRule .* http://host.com$1 [R=301] # Redirect to non www-host

    Good luck in your endeavors.

  4. Jiglet
    Member
    Posted 5 years ago #

    nikc,

    Thanks for the help. I tried this, but I'm still getting a 302 redirect, at least according to this tool: http://www.internetofficer.com/seo-tool/redirect-check/

    Any idea what I may have done wrong? Could something else in WP be overriding the settings specified in my .htaccess file?

  5. Jiglet
    Member
    Posted 5 years ago #

    Nevermind, I think I may have figured it out. I used:

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

Topic Closed

This topic has been closed to new replies.

About this Topic