arkeros
arkeros

Reputation: 13

How to configure .htaccess in this way?

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

Upvotes: 1

Views: 105

Answers (1)

Jon Lin
Jon Lin

Reputation: 143946

RewriteCond %{QUERY_STRING} !pre=[0-9]
RewriteCond %{HTTP_HOST} ^pre([0-9]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /$1?pre=%1 [L,QSA]

Upvotes: 1

Related Questions