Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to figure out what I'm doing wrong with this .htaccess rewrite:

Options -Indexes

RewriteEngine  on
RewriteBase    /test/site/
RewriteOptions MaxRedirects=10

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test/site/public/page.php?rel=$1 [NC,L,B]

I have an Front end script that handles all of the requests. In my case I don't need or have index.php/index.html file in my root project (/test/site/). That causes Apache to throw 403 error because of the first line of the code.

The code will work only if you access the links as follows:


But if you enter


It'll throw 403 error.

I'm pretty sure I'm doing something wrong but I can't figure it out.

share|improve this question

migrated from serverfault.com Jun 4 '11 at 2:50

This question came from our site for system and network administrators.

up vote 1 down vote accepted

Well, your RewriteRule does not apply because that path you are trying is a directory. As set up, your .htaccess redirects things that are neither.

You will need an additional rule or a custom 403 page to handle directories. You may also change your condition to files only. In other words, remove the second RewriteCond line. Which you do depends on what you want to happen for a directory path.

share|improve this answer
In my understanding the configuration above should redirect to page.php whenever a file or directory doesn't exist, right ? Also adding ErrorDocument 403 page.php seems to fix the problem. I'm a bit new to rewriting so I hope I've got it right. – tftd Jun 4 '11 at 8:03
@tftd - Exactly. That directory exists, so it does not get redirected. Do not forget to accept the answer if it worked for you. – Itai Jun 4 '11 at 15:21
Thank you for the help! :) – tftd Jun 5 '11 at 11:21
@tftd "adding ErrorDocument 403 page.php seems to fix the problem" - adding that simply masks the problem. It might look like the correct page is served, but the server would still return and log a 403. (But also, legitimate 403s would break and would need to be handled entirely by your framework.) – w3dk Apr 7 at 14:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.