WordPress.org

Forums

[resolved] Make a site Class B (4 posts)

  1. Will Taft
    Member
    Posted 8 years ago #

    I was looking at the home page of a plugin that does this and saw that "Otto" had posted the following:

    "While this plugin and other like it will indeed work, I really recommend using the .htaccess method instead, if you can get it to work.
    It’s actually very simple to do. Go to no-www org and scroll down the page until you find the post titled “Make your site Class B”. Copy that htaccess code into the .htaccess file at the root of your webpage. Change the “domain” to your own, obviously.
    Done and done."

    This is the no-wwwcode Otto refers to:

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

    I am cautious about changing the htaccess file as what is in there now was put there when I changed my permalinks from the default:

    # BEGIN WordPress<IfModule mod_rewrite.c>
    RewriteEngine OnRewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %
    {REQUEST_FILENAME} !-dRewriteRule . /index.php [L]
    </IfModule># END WordPress

    Do I replace the current htaccess code with the no-www code? Or put the np-www code at the end of the existing? Or, edit the no-www code into the existing?

  2. Will Taft
    Member
    Posted 8 years ago #

    For anyone who finds this in a search... Below is what I did to get this to work. The two lines in the middle are what I added to the existing file. It appears to work correctly. If any of the experts here see a problem with the code, please respond. Otherwise, I'll mark it resolved. Thanks.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
    RewriteRule ^(.*)$ http://yoursite.com/$1 [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
  3. Will Taft
    Member
    Posted 8 years ago #

    As an update, it appears this code needs to be first and apart from the WordPress section of the htaccess file to avoid being rewritten.

    This is what my htaccess file looks like now:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
    RewriteRule ^(.*)$ http://yoursite.com/$1 [R=301,L]
    </IfModule>

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %

    {REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

  4. jplancaster
    Member
    Posted 8 years ago #

    I don't get it. Why not default to www as google and most other larger sites? I allow both but why do some end up going to http://www.site.com?

Topic Closed

This topic has been closed to new replies.

About this Topic