WordPress.org

Ready to get started?Download WordPress

Forums

Redirect to get rid of www. (6 posts)

  1. maureenfrancis
    Member
    Posted 7 years ago #

    I installed the no www plugin and ended up with a problem so I uninstalled it.

    Right now my site with www. on is a PR 4 and without is a PR 5. I would like everything forwarded to without www. My blog is located at mioaklandcounty.com/blog. That is the main page of the site. I am not sure how to edit my htaccess files to remove the www permanently. I had bluehost do it and they majorly screwed everything up.


    root directory htaccess file

    Redirect /home.htm http://www.mioaklandcounty.com/blog/

    RewriteEngine ON
    RewriteCond %{HTTP_HOST} ^975fairfax.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.975fairfax.com$
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^(.*)$ http://www.oakland-county-homes.com/listing/47877522 [R=301,L]
    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    /blog htaccess file

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>
    # END WordPress

  2. waffles
    Member
    Posted 7 years ago #

    All you need is this, with the example sites used changed to your site.

    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^www\.yourdomainhere\.com [nc]
    rewriterule ^(.*)$ http://yourdomainhere.com/$1 [r=301,nc]

    Place it in your .htacess file, remove anything else that attempts to do the same thing, and you should be good.

  3. projectego
    Member
    Posted 7 years ago #

    I just use the Enforce www preference plugin. By far the easiest way to go about it, in my opinion.

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    The .htaccess that waffles gave is by far the best way to do it. Fast, efficent, doesn't require any real processing time...

    That .htaccess should go in the root of your site, BTW. It doesn't need to be anywhere else, usually.

    More info can be found here:
    http://no-www.org

  5. maureenfrancis
    Member
    Posted 7 years ago #

    Thanks everyone.

    the www enforce plugin actually caused me a to have a ton of problems that I could not fix. I researched and learned that the htaccess file is the way to do it. I have read the no-www.org site but I am pretty clueless on this stuff and scared after my bad experience with www enforce plugin.

    Waffles, when you say to remove anything else that does the same thing do you mean the plugin or do you mean something else in the htaccess file.

  6. cam_oai
    Member
    Posted 7 years ago #

    in the header.php, first line after <?php , i added this line:

    <?php
    $url = "http://".$_SERVER['HTTP_HOST'];
    $realurl  = "http://yoursite.com";
    
    if($url != $realurl){
    header("Location:".$realurl);
    exit;
    }
    ?>

    change http://yoursite.com to your domain. this one is OK when your cookies save your url without www. i had that problem so i took this code.

    not the best, but it works for me.

    cheers

Topic Closed

This topic has been closed to new replies.

About this Topic