Direct via .htaccess a query string

-2

I have a system where there will be multiple users. Each user will have their own subdomain. Ex.:

usuario1.sistema.com.br 
usuario2.sistema.com.br

For this I created the subdirectories and in each of them I created a .htaccess by redirecting to the system that is in the root folder. See:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^cliente1.sistema.com.br$ [OR]
RewriteCond %{HTTP_HOST} ^www.cliente1.sistema.com.br$
RewriteRule ^(.*)$ http://www.sistema.com.br/acesso/$1 [P]

The problem is that when it creates this redirect for the system, I can not identify who the client is, ie whether it is client1 or client2 , etc.

How could I do to identify this customer? I do not have much experience with .htaccess , but I believe I could use RewriteCond %{QUERY_STRING} and in the system file get PHP with $_REQUEST . Something like:

RewriteCond %{QUERY_STRING}^cliente=cliente1

And in PHP:

$cliente = $_REQUEST["cliente"];

If this is the solution, how would I apply the RewriteCond %{QUERY_STRING} to my .htaccess ?

    
asked by anonymous 21.08.2018 / 05:10

1 answer

1

I mounted this rule:

RewriteEngine on
RewriteRule ^cliente([0-9]+).sistema.com.br$ http://www.sistema.com.br/acesso/$1 [P]

I added ([0-9] +) any number from 0 to 9 that could be one or more characters, then put it at the end of access in the redirect. The test is below in the image.

Youcanusethistoolandimprovetotaste: link

Update:

In this case King would just adapt the rule like this:

RewriteEngine on
RewriteRule ^([a-z0-9-]+).sistema.com.br$ http://www.sistema.com.br/acesso/$1 [P]

Or as you said in the question you wanted to make a GET per client in php could be:

RewriteEngine on
RewriteRule ^([a-z0-9-]+).sistema.com.br$ http://www.sistema.com.br/acesso?cliente=$1 [P]

Any set of characters from a to z to minus z or zero to nine may contain strokes, and the + outside the brackets means one or more characters.

I hope this helps you!

    
21.08.2018 / 05:38