views:

18

answers:

1

I'm having a small problem with my htaccess files. Currently, it redirects everything back to index.php for processing, except when someone tries to access an actual directory. When the directory exists, it displays the 403 error page instead of rewriting the path to index.php like it's supposed too. What can I modify to make it always go to index.php when the files are accessed via the internet, but still load the correct files in PHP on the server?

Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /

ErrorDocument 403 /index.php?403
ErrorDocument 404 /index.php?404
ErrorDocument 414 /index.php?414

RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule !^(.*) index.php [L]

Sample file structure:

Web Directory
- com
- source
- index.php
- TEST.HTML

The folders such as 'com' and source' will display the 403 because the user doesn't have access to them. The files such as 'index.php' and 'TEST.HTML' execute normally. I want my htaccess to redirect everything in the Web Directory folder back to the index.php file, no matter what.

+1  A: 

I think you want this instead:

Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /

ErrorDocument 403 /index.php?403
ErrorDocument 404 /index.php?404
ErrorDocument 414 /index.php?414

RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule .* index.php [L]

This was on the assumption that you didn't want to be able to access TEST.HTML directly and didn't want to change the URL in the user's browser. If either of those assumptions were wrong, let me know and I'll update the answer with the appropriate rewrite information.

Tim Stone
Thanks, your example helped me realize that I had the negation in front of my rewrite rule `RewriteRule !^(.*) index.php [L]`. I don't know what kind of weird effect 'not any character 0 or more times' can have on the script. Simply removing the '!' fixed the problem.
animuson