Mod rewrite 为什么子域重写不起作用?

Mod rewrite 为什么子域重写不起作用?,mod-rewrite,Mod Rewrite,我希望我的子域直接指向一个文件夹。 我找到了下面的mod_rewrite脚本来设置此行为。 不幸的是,它不起作用 当我导航到fish.example.com时,浏览器显示404 error,并显示以下消息。 在此服务器上找不到请求的URL/ 你知道为什么吗? 我怎样才能让它工作 # Internally rewrite <subdomain>.example.com/<URLpath> to example.com/subs/<subdomain/<U

我希望我的子域直接指向一个文件夹。 我找到了下面的mod_rewrite脚本来设置此行为。 不幸的是,它不起作用

当我导航到fish.example.com时,浏览器显示404 error,并显示以下消息。 在此服务器上找不到请求的URL/

你知道为什么吗? 我怎样才能让它工作

    # Internally rewrite <subdomain>.example.com/<URLpath> to example.com/subs/<subdomain/<URLpath>
RewriteEngine on

RewriteCond $1 !^fish/
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) /fish/%1/$1 [L]
试试这个:

重新启动发动机

重写Base/确保它从域开始

RewriteCond%{HTTP_HOST}^fish.example.com[NC]捕获您的子域

重写规则。*$fish/$1[L]重新路由到文件夹。

更新:

我明白了。。。试试这个:

RewriteCond $1 !^fish/
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) http://example.com/%1/$1 [R=301,L]

基本上是301重定向…%1匹配上一次重写中的子域,$1匹配原始url

Apache访问/错误日志是否提供了有用的信息?是的,Michael,谢谢你的提示。我看到以下消息[Tue Oct 13 09:21:05 2009][error][client 188.134.xxx.xxx]文件不存在:/var/www/fish/fish看起来目录添加了两次。但我不知道为什么。重复:谢谢,布伦特!不幸的是,它不起作用。Apache说重写基线中存在语法错误。RewriteBase/确保它从域开始是的,我写它时在Rewrite和Base之间没有空格,但它没有帮助。仍然存在错误。John,我已按照您建议的方式更改了脚本,但在这种情况下,浏览器将重定向到example.com而不是example.com/fish。请参阅我更新的主题中的完整脚本。
RewriteCond $1 !^fish/
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) http://example.com/%1/$1 [R=301,L]