0

So, I'm trying to redirect any pages to a file, but avoid redirecting anything thats an existing file or directory.

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^(.+)$  $1 [L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$  /index.php?page=$1 [QSA]

However, any directories still get redirected (existing files are fine and can be located.)

1
  • are you asking how to redirect any file (but not directory) requests that don't exist? Jan 6, 2011 at 14:37

1 Answer 1

1

You're using REQUEST_FILENAME to mean REQUEST_URI, and while that is documented to work in some cases (like when used on a vhost), I have a feeling that in this case it's already determined into the final name. See if RewriteCond %{REQUEST_FILENAME} -d makes a difference, or just always use REQUEST_URI.

If not, well, one option is to rewrite to add index.htm/html/php/pl etc to the end, test each for existence and finalize the rule if so, otherwise go to the last step? That's all that I can think of off the top of my head.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .