RewriteCond variable backlink% 2

this is the htaccess file on the server

RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www. RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain.com(.*)$ RewriteRule ^(.*)$ http://domain.com/test\.php?user=%1&path=%2 [R] 

According to my understanding of the above code, if I request asher.domain.com/user , it should rewrite to http://domain.com/test.php?user=asher& path = / user correctly?

Instead, I get http://domain.com/test.php?user=asher&path=% 2 empty. but if I use $ 1 instead of % 2 , I get the correct result.

I could make the most stupid mistake, but I'm not sure where I made a mistake. Help me guys? where is the error in the rewrite rules that% 2 does not work for me?

+4
source share
1 answer

Using the $ syntax gives you a RewriteRule backlinks, and % will give you a RewriteCond backlinks. This is a description of mod_rewrite .

In your case, your RewriteRule should look like this:

 RewriteRule ^(.*)$ http://domain.com/test\.php?user=%1&path=$1 [R] 

Since you want the first group match with the previous RewriteCond and the first group match with the current RewriteRule .

+3
source

Source: https://habr.com/ru/post/1400616/


All Articles