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 shit 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 shit (else why would Google do it?)
So I added an .htaccess redirect in the public root of this domain. If I type “frostedside.com” in a browser, it auto-changes it to “www.frostedside.com” 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 “frostedside.com/blog”, 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} ^frostedside.com [NC]
RewriteRule ^(.*)$ http://www.frostedside.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 frostedside.com/blog without the trailing slash,) the www now shows up like it’s supposed to.
Yay. :-)





Post a comment