Redirecting the url using query string parameters
11 posts
• Page 1 of 1
Redirecting the url using query string parameters
Hi,
Please help me in redirecting the following url
https://domain.com/sales/abc/opps/edit.aspx?id={66740FEF-A424-4854-8239-38DD3E43FA16}
to
https://domain.com/testsales/testopps/main.aspx?oppid={66740FEF-A424-4854-8239-38DD3E43FA16}
The above url contains query string and it is using https. It should redirect to different folder using https and should carry the query string parameter.
Thanks
Rakesh.
Please help me in redirecting the following url
https://domain.com/sales/abc/opps/edit.aspx?id={66740FEF-A424-4854-8239-38DD3E43FA16}
to
https://domain.com/testsales/testopps/main.aspx?oppid={66740FEF-A424-4854-8239-38DD3E43FA16}
The above url contains query string and it is using https. It should redirect to different folder using https and should carry the query string parameter.
Thanks
Rakesh.
Re: Redirecting the url using query string parameters
Hello, Rakesh
Please try it like this:
RewriteBase /
RewriteCond %{HTTPS} .*on.* [NC]
RewriteCond %{QUERY_STRING} ^id=(\{.*\})$ [NC]
RewriteRule ^sales/abc/opps/edit\.aspx$ https\://domain.com/testsales/testopps/main.aspx?oppid=%1 [NC,R=301,L]
Please try it like this:
RewriteBase /
RewriteCond %{HTTPS} .*on.* [NC]
RewriteCond %{QUERY_STRING} ^id=(\{.*\})$ [NC]
RewriteRule ^sales/abc/opps/edit\.aspx$ https\://domain.com/testsales/testopps/main.aspx?oppid=%1 [NC,R=301,L]
Re: Redirecting the url using query string parameters
Hello Anton,
Thanks for the solution. I have one more question.
I wrote a rule as given below and it is working fine if there is a request domain.com/sales/abc/opps/edit.aspx
RewriteCond %{HTTPS} .*on.* [NC]
RewriteRule ^sales/abc/opps/edit\.aspx$ testsales/testopps/main.aspx?oppid= [NC,R,L]
but if there is a request which contains query string (as shown below)
domain.com/sales/abc/opps/edit.aspx?id=46 then the above rule gets passed which should not.
My request url may or may not contain query string. Basically I am looking for the below scenarios
for example:
1) https://domain.com/sales/abc/opps/edit.aspx should redirect to
https://domain.com/testsales/testopps/main.aspx?oppid=
2) https://domain.com/sales/abc/opps/edit.aspx?prm=3&cat=4
to
https://domain.com/testsales/testopps/m ... id=3&cat=4
3) https://domain.com/sales/abc/opps/edit.aspx?id=3 this should not redirect to any thing. it should behave as it is.
Please help...
Thanks for the solution. I have one more question.
I wrote a rule as given below and it is working fine if there is a request domain.com/sales/abc/opps/edit.aspx
RewriteCond %{HTTPS} .*on.* [NC]
RewriteRule ^sales/abc/opps/edit\.aspx$ testsales/testopps/main.aspx?oppid= [NC,R,L]
but if there is a request which contains query string (as shown below)
domain.com/sales/abc/opps/edit.aspx?id=46 then the above rule gets passed which should not.
My request url may or may not contain query string. Basically I am looking for the below scenarios
for example:
1) https://domain.com/sales/abc/opps/edit.aspx should redirect to
https://domain.com/testsales/testopps/main.aspx?oppid=
2) https://domain.com/sales/abc/opps/edit.aspx?prm=3&cat=4
to
https://domain.com/testsales/testopps/m ... id=3&cat=4
3) https://domain.com/sales/abc/opps/edit.aspx?id=3 this should not redirect to any thing. it should behave as it is.
Please help...
Re: Redirecting the url using query string parameters
Ok, please try to fix it like this:
RewriteCond %{HTTPS} .*on.* [NC]
RewriteCond %{QUERY_STRING} ^(?:prm=(\d+&cat=\d+))?$ [NC]
RewriteRule ^sales/abc/opps/edit\.aspx$ https://domain.com/testsales/testopps/main.aspx?oppid=(?%1%1) [NC,R=301,L]
RewriteCond %{HTTPS} .*on.* [NC]
RewriteCond %{QUERY_STRING} ^(?:prm=(\d+&cat=\d+))?$ [NC]
RewriteRule ^sales/abc/opps/edit\.aspx$ https://domain.com/testsales/testopps/main.aspx?oppid=(?%1%1) [NC,R=301,L]
Re: Redirecting the url using query string parameters
Could you please explain me the redirect rule that you provided.
^(?:prm=(\d+&cat=\d+))?$ --> How does this work?
(?%1%1) --> How does this work.
^(?:prm=(\d+&cat=\d+))?$ --> How does this work?
(?%1%1) --> How does this work.
Re: Redirecting the url using query string parameters
Sure:
^(?:prm=(\d+&cat=\d+))?$ --> the outer parentheses with the question mark make the query string optional. The inner parentheses match the necessary part of the query string if it's there.
(?%1%1) --> sort of IF construction: IF %1 exists (meaning, if there's a query string), then add what was matched here (\d+&cat=\d+) to the URL.
^(?:prm=(\d+&cat=\d+))?$ --> the outer parentheses with the question mark make the query string optional. The inner parentheses match the necessary part of the query string if it's there.
(?%1%1) --> sort of IF construction: IF %1 exists (meaning, if there's a query string), then add what was matched here (\d+&cat=\d+) to the URL.
Re: Redirecting the url using query string parameters
Thanks for the information. It was really helpfull.
I am facing another problem.
In the requested url, query string parameter FromId's value is %7b998 which is converting to %257b998. I want it to be the same as in the requested url. I tried putting 'O' in the end of the rule but didn't work.
Can you please help me how to get it?
RewriteCond %{HTTPS} .*on.* [NC]
RewriteCond %{QUERY_STRING} ^FromType=(.*)&FromId=(.*)$ [NC]
RewriteRule ^sales/abc/opps/edit\.aspx$ testsales/testopps/main.aspx?oppid=&FromType=%1&FromId=%2 [NC,R=301,L]
I am facing another problem.
In the requested url, query string parameter FromId's value is %7b998 which is converting to %257b998. I want it to be the same as in the requested url. I tried putting 'O' in the end of the rule but didn't work.
Can you please help me how to get it?
RewriteCond %{HTTPS} .*on.* [NC]
RewriteCond %{QUERY_STRING} ^FromType=(.*)&FromId=(.*)$ [NC]
RewriteRule ^sales/abc/opps/edit\.aspx$ testsales/testopps/main.aspx?oppid=&FromType=%1&FromId=%2 [NC,R=301,L]
Re: Redirecting the url using query string parameters
No, it didn't work.
RewriteRule ^sales/abc/opps/edit\.aspx$ testsales/testopps/main.aspx?oppid=&FromType=%1&FromId=%2 [NC,R=301,L,NE]
RewriteRule ^sales/abc/opps/edit\.aspx$ testsales/testopps/main.aspx?oppid=&FromType=%1&FromId=%2 [NC,R=301,L,NE]
Re: Redirecting the url using query string parameters
I have tried this string and it worked. Thanks.
11 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 31 guests