WordPress, Apache, and mod_rewrite

mod_rewrite

I took some time this morning to sort out a problem that I’ve been having with my WordPress install.  I have the WordPress URL and the Site Address URL on different subdomains, the admin panel being located at a secured subdomain.  Using mod_rewrite I was able to redirect all attempts to access wp-login.php or anything in the /wp-admin tree to the SSL secured subdomain and it worked like a champ. There was one caveat though, any attempt to preview a post was directed over the insecure, main site URL was met with this message, “You do not have permission to preview drafts.”

Given my limitations with a shared hosting plan, my options were limited; however, the solution was simple enough (simple if you understand regular expressions, mod_rewrite, and the HTTP request protocol).  I included a second rewrite rule that matched the requested URL if the query string contains “preview=true” and redirected it over to the SSL secured subdomain.  At this point I was able to preview posts.

For those of you, like myself, that need to understand mod_rewrite a little better, take a look at this tutorial.

Leave a Reply