I'm trying to rewrite requests to subdomains to a specific file. So when I visit http://test.domain.com it shows the campaign.php
RewriteCond %{REQUEST_URI} !^index\.php
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule . /campaign.php?user=%1 [L]
This however gives me a server 500 error
If I change the last line by the following
RewriteRule . http://www.domain.com/campaign.php?user=%1 [L]
That seems to work, but it also changes the url in the browser to http://www.domain.com/campaign.php?user=test
. I want to keep http://test.domain.com as the browser url and show the campaign.php file. What is the best way to achieve this?
Update:
I talked with the support desk of my hoster and they helped fixing it, this is what the script turned into:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !/(campaign|index)\.php
RewriteCond %{HTTP_HOST} ^(.*).domain\.com$ [NC]
RewriteRule (.*) campaign.php?user=%1 [L,QSA]