Apache RedirectMatch

My web site's front page was stale and ugly. It was time for a makeover, but I am not much of a web site beautifier. I thought this blog might be a good entry point, but it was already installed under /blog/page/kasper/. I thought it would be too hard, and probably a bad idea, to make the blog run directly under /, but I still wanted / to point to the blog.

The first thing I tried was the refresh meta tag. I added this line to my /index.html:

<meta http-equiv="refresh"

That worked--it forwarded to the blog--but it looked amateurish. The web browser displayed the old /index.html file briefly before displaying the blog page--very dissatisfying.

The next thing I tried was Apache Redirect. I added this line to kasperowski.com's VirtualHost entry in the httpd.conf file:

Redirect permanent / http://kasperowski.com/blog/page/kasper/

At first, I thought that worked great. When a web browser requested /, it immediately displayed /blog/page/kasper/. It broke everything else, though. Every page under / was redirected to /blog/page/kasper/. For example, /foo redirected to /blog/page/kasper/foo, which didn't exist.

My final idea was Apache RedirectMatch. I wanted /, and only /, to redirect to the blog, and everything else to behave like usual. I replaced the Redirect line in httpd.conf with:

RedirectMatch permanent ^/$ http://kasperowski.com/blog/page/kasper/

That did exactly what I wanted: / is the only thing that redirected to /blog/page/kasper/. Everything else, like /foo, worked that way it did before.

No comments:


Related Posts with Thumbnails