wordpress subdirectory trailing slash problem - FIXED
(Warning: Computer geeky post.)
I'm writing this here for my personal reference just in case I ever had to do this crap again.
Situation: I wanted what's called a "forced www" on all parts of this web site. Some say www is deprecated. I think those people are full of crap (else why would Google do it?)
So I added an .htaccess redirect in the public root of this domain. If I type my domain in a browser, it auto-changes it to have the www in it just like it's supposed to.
My WordPress installation happens to reside in a subdirectory, blog.
Even with the .htaccess redirect, WordPress insists on not adding the www to the web address.
I scoured the internet looking for a solution to this, because no matter what I did, if I typed in my domain with /blog after it, no www would show up. Bleah.
I finally found a solution.
Don't use an .htaccess file in the WordPress subdirectory at all. Put everything in your public root .htaccess instead.
This is what I have now:
# FORCE WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[my domain here].com [NC]
RewriteRule ^(.*)$ http://www.[my domain here].com/$1 [L,R=301]
# WORDPRESS
Rewritebase /blog
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
...and it works. Whether I use a slash or not (such as [my domain].com/blog without the trailing slash,) the www now shows up like it's supposed to.
Yay. 🙂