htaccess 重定向除文件/目录之外的所有内容
我正在尝试创建一个重写规则来完成两件事:
- 将
(www.)?domain.com
重定向到log.domain.com
- 让任何其他目录或文件请求无需重定向即可通过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,因为用户永远不必这样做。 这使得规则的标准变得更加简单,混沌和秋葵都通过下面的第一条规则得出了这一点。 再次感谢!
I am trying to create a rewrite rule that accomplishes two things:
- Redirect
(www.)?domain.com
tolog.domain.com
- 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这个:
Try this: