I have a blog. The blog is stored under the /blog/ prefix on my website. It has the usual URLs for a blog, so articles have URLs in the format /blog/:year/:month/:day/:title/.
First and foremost, I want to automatically redirect visitors to the www subdomain (in case they leave that off), and internally rewrite the root URL to /blog/, so that the front page of the blog appears on the front page of the site. I have accomplished that with the following set of rewrite rules in my .htaccess file:
RewriteEngine On
# Rewrite monkey-robot.com to www.monkey-robot.com
RewriteCond %{HTTP_HOST} ^monkey-robot\.com$
RewriteRule ^(.*)$ http://www.monkey-robot.com/$1 [R=301,L]
RewriteRule ^$ /blog/ [L]
RewriteRule ^feeds/blog/?$ /feeds/blog/atom.xml [L]
That works fine. The problem is that the front page of the blog now appears at two distinct URLs: / and /blog/. So I'd like to redirect the /blog/ URL to the root URL. Initially I tried to accomplish this with the following set of rewrite rules:
RewriteEngine On
# Rewrite monkey-robot.com to www.monkey-robot.com
RewriteCond %{HTTP_HOST} ^monkey-robot\.com$
RewriteRule ^(.*)$ http://www.monkey-robot.com/$1 [R=301,L]
RewriteRule ^$ /blog/ [L]
RewriteRule ^blog/?$ / [R,L]
RewriteRule ^feeds/blog/?$ /feeds/blog/atom.xml [L]
But that gave me an infinite redirect (maybe because of the preceding rule?). So then I tried this set:
RewriteEngine On
# Rewrite monkey-robot.com to www.monkey-robot.com
RewriteCond %{HTTP_HOST} ^monkey-robot\.com$
RewriteRule ^(.*)$ http://www.monkey-robot.com/$1 [R=301,L]
RewriteRule ^$ /blog/ [L]
RewriteRule ^blog/?$ http://www.monkey-robot.com/ [R,L]
RewriteRule ^feeds/blog/?$ /feeds/blog/atom.xml [L]
But I got a 500 Internal Server Error with the following log message:
Invalid command '[R,L]', perhaps misspelled or defined by a module not included in the server configuration
What gives? I don't think [R,L] is a syntax error.
/to go to/blog/and/blog/to go to/... i'm confused. – cpbills May 18 '10 at 18:31/blog/to/) or everything under too? For instance, do you want to use/blog/archives/or just/archives/? – Karol Piczak May 18 '10 at 18:35/blog/should be redirected to the root, which should look (internally, not via a redirect) in the/blog/subdirectory for its file. (Actually, now that I think about it, maybe rewriting to/blog/index.htmlsolves the issue...hrm.) – mipadi May 18 '10 at 20:00www.monkey-robot.com/:year/:month/:day/:title/orwww.monkey-robot.com/blog/:year/:month/:day/:title/? – Karol Piczak May 18 '10 at 20:06/blog/:year/:month/:day/:title/. Only/blog/would be redirected to the root (to avoid having two URLs with the same content). I think a loop is created, so any suggestions to avoid that are fine (although the error message seems to allude to another problem). – mipadi May 18 '10 at 21:45