来自子域的静态文件,来自根目录的 fcgi

来自子域的静态文件,来自根目录的 fcgi

我想发送请求

foo.com -> foo.com/dispatch.fcgi

以及对子域名的请求

bar.foo.com -> foo.com/bar

我的.htaccess 文件中有这个;

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteBase /

# if request matches this (NC - make all req lower case)
RewriteCond %{HTTP_HOST} ^bar\.foo\.com$ [NC]
# then redirect here
RewriteRule ^(.*)$ http://foo.com/bar/$1

# if request isn't to the bar URI
RewriteCond %{REQUEST_URI} !^/bar/ [NC]
# and it isn't a file name (? guessing here)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]

我的fcgi脚本运行正常,但每次尝试访问bar.foo.com都会导致 302 响应

302 Found

The document has moved here (http://bar.foo.com).

我很确定是我的ReWriteRuleforbar.foo.com把事情搞糟了,但我不知道如何修复它(并保留 fcgi 路由)。

答案1

如果向其发出请求,http://bar.foo.com则将其设置为分派 fcgi。我添加了一个RewriteCond来检查此实例,一切开始正常工作。也许有一天这会对某人有用...!

# if request matches this (NC - make all req lower case)
RewriteCond %{HTTP_HOST} ^bar\.foo\.com [NC]
# then redirect here to subdomain
RewriteRule ^/(.*)$ /bar/$1 [L]

# if request isn't to the bar URI
RewriteCond %{REQUEST_URI} !^/bar/ [NC]
# and the HOST request isn't bar.foo.com
RewriteCond %{HTTP_HOST} !^bar.foo.com [NC]
# and it isn't a file name (? guessing here)
RewriteCond %{REQUEST_FILENAME} !-f
# send it to the fcgi
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]

相关内容