I hope you know that you have to change domain.com to the actual domain name and extension that your site uses.
Yes, I know that. Thanks for checking, though. That was the result of a quick cut-and-paste.
Try this. Again make sure your info is in there…
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]
Or this one:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
</IfModule>
I’m just copying these from other people’s examples. I am not testing them. You can find lots of examples here.
BTW, I’m surprised that you don’t have a .htaccess file in your WordPress folder. The code that WP generates will also remove the www. If WordPress is installed in the root folder, .htaccess should contain these lines:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
and if it is in a sub-folder named /blog it should look like this:
# 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
Thanks, SS_Minnow. I’ll give those a try. I was also surprised to find no .htaccess file. This installation of WP was a one-click install with Host Monster. Wonder if that has anything to do with it, since every other installation I’ve done has had the file.
Remember that the last two that I posted should be in your WordPress folder, which is not necessarily the root. If WordPress is in a subfolder, you can use this in the root to redirect all requests from the root to the subfolder. Again I’ll use /blog for the example:
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} domain.ext$
RewriteCond %{REQUEST_URI} !blog/
RewriteRule ^(.*)$ blog/$1
You can also make your domain name point to the sub-folder directly OR move the WordPress files to the root. In both cases you would have to update the database to recognize the new the URL. Information on how to do that is here.
Keep in mind that if you are changing the path so that WordPress is no longer in a sub-folder you should take the references to the sub-folder name out of the .htaccess file as well.