David Janes' Code Weblog

October 24, 2008

Tip – use mod_rewrite to redirect to subdirectory

apache,tips · David Janes · 11:50 am ·

I’ve organized a part of http://code.davidjanes.com/ as follows:

  • / – the main page
  • /blog/ – the blog
  • /genx/demo/ – the demo for GenX

However, I don’t have a /genx/ page (yet) and I plan to do a few more projects with this type of hierarchy. So what to do? Enter Apache mod_rewrite.

In the /genx/ directory I added a .htaccess file with the follow content:

RewriteEngine on
RewriteBase /
RewriteRule ^$ http://code.davidjanes.com/genx/demo/

Note that this may not work in all hosted environments, because they may not allow per-directory access to .htaccess. In that case, I’d consider adding a “index.html” file to the directory with a meta refresh, as follows:

<html>
<head>
<meta http-equiv="refresh" content="0;url=http://code.davidjanes.com/genx/demo/">
</head>
</html>

0 comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress

Switch to our mobile site