Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I may have this set up in a weird/bad way, but the idea I'm going for is to take wildcard subdomains and seamlessly convert them to a different URL behind the scenes that my app understands. My rewrite rule file looks like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/user$1?user=%1 [QSA,P]

This works perfectly from the perspective of site visitors and my app. Behind the scenes, subdomain.domain.com gets rerouted to domain.com/user?user=subdomain. Unfortunately, every request for made to a subdomain generates an error in apache that gets logged. Example log entry (ip addresses and URLs changed to protect the innocent):

[Sun Jun 10 23:29:50 2012] [error] 1.2.3.4 - - [10/Jun/2012:23:29:50] "GET /user/path-here?user=subdomain-here HTTP/1.1" 200 12830 "http://subdomain-here.domain.com/path-here" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0"

I'm assuming it's doing this because the modified and original requests have different URLs associated with them.

How can I make this error go away (or how can I better set up my server to get the end result I need)?

share|improve this question
    
What is the intended outcome? Requests for subdomain.domain.com go to www.domain.com/user___? –  KM. Jun 11 '12 at 17:23
    
I didn't make that clear, did I? Yes, subdomain.domain.com should go to www.domain.com/user?user=subdomain. The rewrite rule functions correctly, as far as the user and my app are concerned. But apache keeps logging the mismatched headers as errors. –  jeremiahs Jun 12 '12 at 0:52
1  
Mm ... I wonder if your mismatch headers are due to the proxy via P in the 4th line ... mm ... try ProxyPreserveHost On before the rewrite rules. More here: httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypreservehost –  KM. Jun 12 '12 at 13:30
    
That's almost certainly the case, but without the P, the user is actually redirected instead of just the request. Adding ProxyPreserveHost On causes the connection to stall and the server to stop responding after the first request to a subdomain. Any way to manually set/rewrite the headers? –  jeremiahs Jun 13 '12 at 6:32
    
I wouldn't tweak headers quite yet. Instead, try: 1. Use Firebug or Developer Tools in our browser to see what is happening with a request and 2. Set your LogLevel to debug and see what you get for errors, if any, in the logs: httpd.apache.org/docs/current/mod/core.html#loglevel –  KM. Jun 13 '12 at 16:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.