1

I have installed wildcards successfully. And I managed to make dynamic subdomain to work with a simple trick.

.htaccess:

Options +FollowSymLinks
        RewriteEngine On
        RewriteBase /

        # *.example.com
        RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
        RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]+)\.example\.com$ [NC]
        RewriteCond %{REQUEST_URI} !^/?subdomain\.php$
        RewriteRule .? subdomain.php?subdomain=%1&path=%{REQUEST_URI} [L,QSA]

Currently in something.example.com is shown the output of subdomain.php, great.

But I want to have it working as I can enter at

pre102.example.com/folder/anotherfolder/script.php?param=1

and show the output of

example.com/folder/anotherfolder/script.php?param=1&pre=102

Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
arkeros
  • 13
  • 2
  • So you want `pre102.example.com/folder/anotherfolder/script.php?param=1` to **redirect** to `example.com/folder/anotherfolder/script.php?param=1&pre=102` (Meaning it changes the browser's address bar)? – Jon Lin Jul 09 '12 at 23:36
  • No, the browser's bar shouldn't change. – arkeros Jul 09 '12 at 23:51
  • Are `pre102.example.com` and `example.com` served from the same document root? – Jon Lin Jul 09 '12 at 23:59

1 Answers1

1
RewriteCond %{QUERY_STRING} !pre=[0-9]
RewriteCond %{HTTP_HOST} ^pre([0-9]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /$1?pre=%1 [L,QSA]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • This does not work. It redirects me to pre.example.com and shows the conent of example.com – arkeros Jul 10 '12 at 18:27
  • Sorry, this works perfectly. I had a problem with sharing php sessions across subdomains. Solved done http://stackoverflow.com/a/1457582/1502554 – arkeros Jul 31 '12 at 10:37