For the past hour, I have been trying to figure out how to tweak the Wordpress-defined htaccess file for a 301 redirect on a non-www url. We do 301 redirects with our own domain to create a single url for both www.domain.com and domain.com, by redirecting the latter to the former. Here’s a clearer explanation of this case with an example of two university websites:
- To take a case that doesn’t use this non-www url redirect, go to both stanford.edu and www.stanford.edu and notice that both instances exist.
- On the contrary, go to psu.edu and note that it automatically redirects you to www.psu.edu.
How is this relevant to SEO? By essentially creating a single version of your webpages across a single domain, you avoid the supplemental results problem by helping search engines index the pages in your website without confusion of duplicate content.
The problem subject of this entry is that Wordpress automatically generates a htaccess file when you tell it to create search engine-friendly url’s like www.itmilk.com/daehee-likes-pineapple-pizza instead of www.itmilk.com/index.php?p=103. (This is accessible through the Options → Permalinks menu.) This is great for the custom permalink url purposes, but trying to modify it is a pain because the format doesn’t match up with any of the 301 redirect tutorials out there. Doing anything minor to it seems to break my blog.
Taking what Wordpress provided for me, I tried to add some new rules into the existing custom permalink rules (new lines in blue):
# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{http_host} ^XXX.com [nc,OR]
RewriteCond %{http_host} ^www.XXX2.com [nc,OR]
RewriteCond %{http_host} ^XXX2.com [nc]
RewriteRule ^(.*)$ http://www.XXX.com/$1 [r=301,nc]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Using my rudimentary understanding of Apache mod_rewrite rules, the above should work. But it doesn’t; the server gives me a 500 document handling error when I try to access any of the url’s in the rewrite conditions.
So, I decided to cop out and use a Wordpress plugin that does all the redirecting for me! Download the Objection Redirection plugin, which lets you simply type in the source and target url’s along with the type of redirect. This is an extremely powerful plugin that seems to use PHP redirection.
Although I took the easy way out, I’d still like to know how to make the htaccess file above work. Let me know if mod rewrite is your bitch.
The Conversation {2 comments}
Hi,
Just wondering if if you ever found a solution to redirecting properly within .htaccess as I too am looking for a solution and dont like the idea of php redirection?
Cool!
I thought understanding my instructions were harder than figuring out mod rewrite, but I’m glad to see I’m wrong about that.
Leave Your Own Comment
You can follow any responses to this entry via its RSS comments feed. You can also leave a trackback if the inclination is there.