0

I would like to send requests for

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

and requests for a subdomain

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

I have this in my .htaccess file;

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]

with this my fcgi script is working fine, but every attempt to access bar.foo.com results in a 302 response

302 Found

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

I'm pretty sure that it's my ReWriteRule for bar.foo.com that's mucking things up, but I can't work out how to fix it (and preserve the fcgi route).

1 Answer 1

0

If a request was made to http://bar.foo.com it was being setn to dispatch fcgi. I added a RewriteCond to check for this instance and everything started working. Maybe this will be useful to someone, one day... !

# 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]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .