1

Hello I have a problem with wildcard subdomains with htaccess and mod_rewrite.

I want www.domain.com/index.php?foo=x&bar=y translated to x-y.domain.com

My htaccess looks like this

RewriteCond %{HTTP_HOST} !^www.domain.com$ 

RewriteCond %{HTTP_HOST} ^(.*?)-(.*?).domain.com$

RewriteRule (.*) /index.php?foo=%1&bar=%2

This work but with one minor issue, if I go to x-y.domain.com. Its show www.domain.com, but if I go to x-y.domain.com/z ( 'z' can be every value, even 'asdfasdfasdfasdfasdf' ) it shows the right page, my application doesnt use z for anything its just there for no reason, but its necessary to show the right page.

Solution

RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*?)-(.*?).domain.com$ [NC]
RewriteRule (.*)    index.php?foo=%1&bar=%2 [NC]

I dont know why it works but it works

Robbert Stevens
  • 316
  • 3
  • 17

0 Answers0