1

我正在尝试创建一个完成两件事的重写规则:

  1. 重定向(www.)?domain.comlog.domain.com
  2. 让 domain.com 上的任何其他目录或文件请求通过而无需重定向

这不是 Apache 服务器(它是 LiteSpeed),但据说它.htaccess完全支持文件。

这是我对规则的看法:

RewriteEngine on

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

发生的情况是,如果我请求特定文件(如 dir/index.php),它会被允许通过,但目录请求仍会重定向到 log.domain.com。我认为$第二个 RewriteCond 会阻止这种情况发生,但事实并非如此。

编辑:仅出于存档目的,我的意图不是将任何不存在的目录/文件重定向到 log.domain.com,因为用户永远不必这样做。这使得规则的标准变得更加简单,混乱和秋葵都在下面给出了他们的第一条规则。再次感谢!

4

2 回答 2

2
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^$ http://log.domain.com/
于 2009-02-11T15:17:50.423 回答
0

试试这个:

# skip the next rule if host is not example.com or www.example.com
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$
RewriteRule ^ - [S]

# redirect if requested URI does not match a regular file or directory
# or if the requested URI path is just "/"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} =/
RewriteRule ^ http://log.example.com/
于 2009-02-11T16:06:43.673 回答