Htaccess Redirect For Everything But Files/directories

- 1 answer

I am trying to create a rewrite rule that accomplishes two things:

  1. Redirect (www.)? to
  2. Let any other directory or file request on through without redirection

This not an Apache server (it's LiteSpeed), but supposedly it supports .htaccess files wholly.

This was my shot at the rule:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule .*

What's happening is that if I request a specific file (like dir/index.php) it's let through, but directory requests are still redirected to I thought the $ of the second RewriteCond would keep this from happening, but that seems to not be the case.

EDIT: Just for archival purposes my intention was not to redirect any nonexistent directories/files to the since users should never have to do that. This made the criteria a lot simpler for the rule, which chaos and gumbo both arrived at with their first rules below. Thanks again!



RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^$