X
X
xsash2014-09-22 15:56:57
Domain name market
xsash, 2014-09-22 15:56:57

How to pass a subdomain name using .htaccess to a script without overwriting other parameters?

I make virtual subdomains with

RewriteCond %{HTTP_HOST} ^test\.example\.com$
RewriteCond %{REQUEST_URI} (.*)/$
RewriteRule ^(.*)$ ?sub=test [L]

RewriteCond %{HTTP_HOST} ^demo\.example\.com$
RewriteCond %{REQUEST_URI} (.*)/$
RewriteRule ^(.*)$ ?sub=demo [L]

Not universal, yes...
The problem is that if I pass GET parameters, they are overwritten. Did it like this
RewriteCond %{HTTP_HOST} ^test\.example\.com$
RewriteCond %{REQUEST_URI} (.*)/$
RewriteRule ^(.*)$ ?sub=test&%{QUERY_STRING} [L]

It turns out conditionally such a transformation
http://test.example.com/?q1=1&q2=2
в
http://example.com/?sub=test&?q1=1&q2=2

Not exactly pretty "&?", but it works.
The next step, I wanted to tie this "hack" with the finished CMS, but there was a conflict of rules
example.com/user/admin/, opens the profile, GET data comes
[subaction] => userinfo
[user] => admin

test.example.com/user/admin/, opens the main page, GET data comes in
[test] => test
My edits are before the processing rule
RewriteRule ^user/([^/]*)(/?)+$ index.php?subaction=userinfo&user=$1 [L]

Accordingly, if you swap
test.example.com/user/admin/, opens the profile, GET data arrives
[subaction] => userinfo
[user] => admin

but now my subdomain data is falling off

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question