Search code examples
apache.htaccesslamp

How can I redirect requests to a sub-directory with .htaccess?


I'm running a basic test to make sure the server supports .htaccess. Unfortunately, we're having a bit of an issue:

This is the structure of the website:

  • /
  • .htaccess
  •     /test
  •     /test/index.html

What I want to do is display (/test/index.html) when the user hits the root directory.

I'm using the following .htaccess script:

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteRule ^$ test/$1 [L]
   RewriteRule (.*) test/$1 [L]
</IfModule>

As a result, I'm getting Internal Server Error. Am I doing something wrong?


Solution

  • You are getting 500 error because $1 is undefined in first case. Change it to:

    <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteRule ^$ test/$1 [L]
       RewriteRule ^(.*) test/$1 [L]
    </IfModule>