I’m trying to force www. on all the pages of my site.
I have wordpress install in a folder on my main site (/blog). In the /blog folder there is an .htaccess file with the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
In the main dir of the site. I have a .htaccess file that has the follow:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.sitename.com [NC]
RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]
RewriteRule ^blog/index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)$ /blog/index.php [L]
In wordpress is have the option set for www. The www. appears on every page except the when I go straight the the site.com/blog address
Go Settings -> General:
WordPress Address (URL)
Site Address (URL)
And set both of them to http://www.yoursite.com (instead of yoursite.com), wordpress automagically takes care for setting all the urls to http://www.yoursite.com and that’s it.
If that isn’t enough, you shouldn’t edit the .htaccess file anyway, because anytime you save or reload your permalink settings, WordPress will overwrite your .htaccesss (some plugins may do that as well).
If you do want to rewrite your URL, you should do it with WP Rewrite (Codex), or if you want a little more simple approach, there is a good plugin for that called Redirection (WordPress.org Plugin Directory).
In Redirection plugin you can just set the options to *.mydomain.com/* to redirect to http://www.mydomain.com/* with a 301, and that will take care of your htaccess as long as you keep the plugin active.
Hope this helps 🙂
In the .htaccess of the WordPress installation (/blog/ in your case), you can add the following code ABOVE the line that reads
# BEGIN WordPress
Obviously, replace “domain.com” with your actual domain name and “subdirectory” with the name of the subdirectory where WordPress is installed. (/blog/ in the OP’s request).
Have Option for you:
using wp-config.php add:
define(‘WP_HOME’,’http://www.domainname.com‘);
define(‘WP_SITEURL’,’http://www.domainname.com‘);
using wp-admin
Log into your wp-admin
Browse to ‘Settings’ -> ‘General’
Under ‘WordPress Address (URL)’ and ‘Site Address (URL)’ add www to the address as shown below