Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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:

http://localhost/test/site/public/index
http://localhost/test/site/public/something/else/index.html

But if you enter

http://localhost/test/site/public/

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
add comment

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

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

1 Answer

up vote 0 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
add comment

Your Answer

 
discard

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.