Ad

Htaccess Redirect For Everything But Files/directories

- 1 answer

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

  1. Redirect (www.)?domain.com to log.domain.com
  2. Let any other directory or file request on domain.com 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 .* http://log.domain.com/

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 log.domain.com. 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 log.domain.com 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!

Ad

Answer

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^$ http://log.domain.com/
Ad
source: stackoverflow.com
Ad