WordPress uses .htaccess to rewrite the urls for pages, as WordPress calls it, making ‘pretty urls.’ This can however, lead to some confusion when trying to sort out canonicalization issues so that WordPress only uses www or non-www urls. There are a number of plugins that claim to take care of this for you but you can’t beat editing htaccess yourself.
Redirect www.domain to non-www.
Replace the existing WordPress htaccess code with the following (obviously changing the domain to yours):
# BEGIN WordPress
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
and for non-www to www.domain
# BEGIN WordPress
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
You must be logged in to post a comment.