back references
3 posts
• Page 1 of 1
back references
Hi,
I am trying to reverse engineer some code and need some help understanding back references. from the documentation I understand that back references are to RewriteCond statements when used within a Rewrite rule. Now based on the below code:
RewriteCond %{REQUEST_URI} !^/favicon.ico [NC]
RewriteCond %{REQUEST_URI} !^/SomeHeader/ [NC]
RewriteCond %{HTTP_COOKIE} ^((?!lastview).)*$ [NC]
RewriteCond %{HTTP:Host} (.*)
RewriteCond %{REQUEST_URI} (.*)
RewriteCond %{QUERY_STRING} (.*)
RewriteRule .? https\://%2/SomeHeader/default\.aspx\?requesturl=https\://%2%3\?%4 [R=301]
what will the values be inside %1,%2,%,3 and %4 and is there any more %N where N > 4. The reason I am thrown off is %{REQUEST_URI} is used 3 times.
Any help will be greatly appreciated
Thanks
I am trying to reverse engineer some code and need some help understanding back references. from the documentation I understand that back references are to RewriteCond statements when used within a Rewrite rule. Now based on the below code:
RewriteCond %{REQUEST_URI} !^/favicon.ico [NC]
RewriteCond %{REQUEST_URI} !^/SomeHeader/ [NC]
RewriteCond %{HTTP_COOKIE} ^((?!lastview).)*$ [NC]
RewriteCond %{HTTP:Host} (.*)
RewriteCond %{REQUEST_URI} (.*)
RewriteCond %{QUERY_STRING} (.*)
RewriteRule .? https\://%2/SomeHeader/default\.aspx\?requesturl=https\://%2%3\?%4 [R=301]
what will the values be inside %1,%2,%,3 and %4 and is there any more %N where N > 4. The reason I am thrown off is %{REQUEST_URI} is used 3 times.
Any help will be greatly appreciated
Thanks
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: back references
Hello,
The values that are marked %N are the values of anything inside brackets (...) in RewriteCond. If brackets are inside RewriteRule than it's $N.
Meaning that in this particular case first set of brackets is in "RewriteCond %{HTTP:Host} (.*)", which captures everything in this variable. So %2 would be the value of %{REQUEST_URI} and %3 - %{QUERY_STRING} (.*). More about request processing can be found in these articles:
- http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-i/
- http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-2/
The reason you have three RewriteCond %{REQUEST_URI} in your set is not really relevant. Some people could have combined them in one. First two simply check if requested URL is not looking for favicon or /SomeHeader/ folder.
Regards
Andrew
The values that are marked %N are the values of anything inside brackets (...) in RewriteCond. If brackets are inside RewriteRule than it's $N.
Meaning that in this particular case first set of brackets is in "RewriteCond %{HTTP:Host} (.*)", which captures everything in this variable. So %2 would be the value of %{REQUEST_URI} and %3 - %{QUERY_STRING} (.*). More about request processing can be found in these articles:
- http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-i/
- http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-2/
The reason you have three RewriteCond %{REQUEST_URI} in your set is not really relevant. Some people could have combined them in one. First two simply check if requested URL is not looking for favicon or /SomeHeader/ folder.
Regards
Andrew
Re: back references
appreciate it Andrew now it makes sense
just in case someone else revisits this post later. based on your description I think the first set of brackets(Parentheses) is actually in
RewriteCond %{HTTP_COOKIE} ^((?!lastview).)*$ [NC] so based on the above example it would be:
RewriteCond %{HTTP_COOKIE} ^((?!lastview).)*$ [NC] ===========> %1
RewriteCond %{HTTP:Host} (.*) ===========> %2
RewriteCond %{REQUEST_URI} (.*) ===========> %3
RewriteCond %{QUERY_STRING} (.*) ===========> %4
Thanks again for your help![Smile :)](./images/smilies/icon_e_smile.gif)
just in case someone else revisits this post later. based on your description I think the first set of brackets(Parentheses) is actually in
RewriteCond %{HTTP_COOKIE} ^((?!lastview).)*$ [NC] so based on the above example it would be:
RewriteCond %{HTTP_COOKIE} ^((?!lastview).)*$ [NC] ===========> %1
RewriteCond %{HTTP:Host} (.*) ===========> %2
RewriteCond %{REQUEST_URI} (.*) ===========> %3
RewriteCond %{QUERY_STRING} (.*) ===========> %4
Thanks again for your help
![Smile :)](./images/smilies/icon_e_smile.gif)
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 9 guests