Today I finally got around to solving a problem that has bugged me with a site in development. Embarrassingly, it's an easy fix, and should have been an easy find. But in my defense, a LOT of other people are having this issue!
So I'm sharing my fix...
When I added a "enforce www" code to my htaccess file -- which helps prevent dupe content, good SEO practice -- I found myself locked out of WordPress. It was in a loop when I went to wp-admin and logged in, it would just return to the wp-login.php page. The username and password was accepted, it just failed to go anywhere.
I had to leave the non-www version up, and face the consequences of duplicate content from search engines. Ugh!
The fix was simple. When I had set up WordPress, I had specified "site.com" as the WordPress address (URL) and Blog address (URL). Under the GENERAL SETTINGS (settings > general) area in the WordPress back-end, I simply changed this to "www.site.com". Obviously, I had to remove the htaccess code to allow for this.
Had I been unable to log into WordPress, neither through www or non-www, I'd have needed to login to the mySQL database directly, search for the entry, and then change it with an SQL query. Luckily, it did not come to that. (Tip: SQLyog is EXCELLENT
software for managing mySQL databases!!)
NOTE: If you find yourself in this bind,
sign up as a forum member, and post that you need some help with an SQL query, to fix this issue!
The htaccess code now works perfectly...
PHP Code:
RewriteCond %{HTTP_HOST} ^site.com [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]
... and I can login to WordPress. No more dupe content!
Hope this helps you out.