How do I rewrite everything after the question mark (?) as one parameter?
For example, I have a url as: http://www.example.com?abcdefg/test/module?wiating4request
Notice after the first question mark we have another in the query string. I basically need to post to that url and I cannot modify the url so I need to make do with what is provided.
I saw something similar here: How can I use mod_rewrite to remove everything after the ? (question mark) in a URL?
Keep in mind this is for IIS 7.
Any ideas?
It's possible to do this with a rewrite rule in case you only want to match URL's with just one question mark too many, like your example. You can then use this rule:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Clean extra question mark from query string" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="^(.+?)(\?(.+))*$" />
</conditions>
<action type="Rewrite" url="/{URL}?{C:1}&{C:3}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If you want to match an unlimited number of too many question marks I think you will need to revert to a custom rewrite provider as detailed in the linked article. You might then end up with something like:
<rule name="Clean extra question mark from query string" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="^$" negate="true" />
</conditions>
<action type="Rewrite" url="/{URL}?{ReplaceProvider:{QUERY_STRING}}" appendQueryString="false" />
</rule>
Related
I have already created a topic about query strings, unfortunately the question was closed and no one answers anymore.
For example, I want to redirect from splash.aspx?page=3 to a simpler url e.g. to splash3.aspx. I unfortunately have no backend code where the query string can respond, so I need an alternative. How can I configure url rewrite?
In your web.config, add the following nodes:
<rewrite>
<rule name="Redirect splash page 3" stopProcessing="true">
<match url="splash\.aspx$" />
<conditions>
<add input="{QUERY_STRING}" pattern="page=3" />
</conditions>
<action type="Redirect" url="splash3.aspx" redirectType="Temporary" />
</rule>
</rewrite>
For more information see https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference
I'm trying to redirect wordpress posts to a coldfusion page by using an IIS URL redirect. the posts link is
domain.com/?p=345
so I have set up the following redirect using the rolling Pattern
/?p=([0-9]+)
To point to the following page...
/blog.cfm?ID={R:1}
But sadly when I check out the page, it simply refreshes and doesn't redirect to the blog.cfm page.
Any help or advice much appreciated.
Below is the full web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wp post redirect" stopProcessing="true">
<match url="/?p=([0-9]+)" />
<action type="Redirect" url="blog.cfm?ID={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Your rule should be like that:
<rule name="wp post redirect" stopProcessing="true">
<match url="^$" />
<conditions>
<add input="{QUERY_STRING}" pattern="p=([0-9]+)" />
</conditions>
<action type="Redirect" url="blog.cfm?ID={c:1}" appendQueryString="false" />
</rule>
Explanation:
Your rule had mistake <match url= contains only url path without query string.
<match url="^$" /> that means apply this rule for requests, which valid for ^$ regexp. It is only for homepage
<add input="{QUERY_STRING}" pattern="p=([0-9]+)" /> that means apply this condition. Only if query string valid for p=([0-9]+) regexp
<action type="Redirect" url="blog.cfm?ID={c:1}" appendQueryString="false" /> Redirect to log.cfm?ID={c:1} where {c:1} is first match from regexp from condition
I am trying to get a site to work with a different URL, basically one is the real URL(fakesite.com) and the other is a Branded URL(NewFakeSite.com). So far ive managed to get it to work so that:
http://fakesite.com/uv/ExpressBranding/ExpressHome.aspx
and
http://NewFakeSite.com/uv/ExpressBranding/ExpressHome.aspx
Both go to the same site and are both able to work as functioning sites. The Problem comes with Querystrings, I cant seem to get the second site to pass along the Querystring so if I go to a URL with a Querystring like:
http://fakesite.com/uv/EnviSetup/Wizard/GeneralInformation.aspx?DashboardId=0
For the Second site it cant find the page and instead gives me:
https://NewFakeSite.com/uv/EnviSetup/Wizard/GeneralInformation.aspx
with no QueryString at all.As such I need to add the Querystring. My webconfig is below, its not just my code so certain pieces of it like the HTTP to HTTPS and adding uv were not written by me.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<remove name="Redirect to HTTPS" />
<remove name="Redirect to add uv folder to dotcom" />
<rule name="Redirect to add uv folder to dotcom" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{map add uv after dotcom:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<serverVariables />
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{SERVER_NAME}" pattern="opterra\.esightenergy\.com" negate="true" />
</conditions>
<serverVariables />
<action type="Rewrite" url="https://{HTTP_HOST}/{R:1}" appendQueryString="false" />
</rule>
<rule name="AddQueryStringForENVIDashBoards">
<match url="https://prod.utilityvision.com/uv/EnviSetup/EnviDashboardList.aspx(\?(.*))" />
<action type="Rewrite" url="HTTPS://opterra.esightenergy.com/uv/EnviSetup/Wizard/{C:1}" appendQueryString="false" />
<conditions>
<add input="{URL}" pattern="https://prod.utilityvision.com/uv/EnviSetup/Wizard/(.*)" />
</conditions>
</rule>
</rules>
</rewrite>
<httpRedirect enabled="false" destination="" exactDestination="false" childOnly="false" />
</system.webServer>
</configuration>
Any Help would be greatly appreciated I am new to IIS so I hope this is even possible. Thanks!
EDIT: I have tried setting the appendQueryString="True" but still no Querystring. Thanks mjw.
Edit 2: The main goal is to make make it so the URL shows up as something different then it was originally programmed as, The problem is the Query String doesnt come with the rest of the new URL. I have added some code changes to see if this would fix the problem but it did not the URL remained the same. The code sample above is not the original I added this:
<rule name="AddQueryStringForENVIDashBoards">
<match url="https://prod.utilityvision.com/uv/EnviSetup/EnviDashboardList.aspx(\?(.*))" />
<action type="Rewrite" url="HTTPS://opterra.esightenergy.com/uv/EnviSetup/Wizard/{C:1}" appendQueryString="false" />
<conditions>
<add input="{URL}" pattern="https://prod.utilityvision.com/uv/EnviSetup/Wizard/(.*)" />
</conditions>
</rule>
You have server variable for query string so you can use it to append value to the redirection url:
QUERY_STRING
So for your request http://fakesite.com/uv/EnviSetup/Wizard/GeneralInformation.aspx?DashboardId=0
Important Server variable values are:
HTTP_HOST: www.fakesite.com
PATH: /uv/EnviSetup/Wizard/GeneralInformation.aspx
QUERY_STRING: DashboardId=0
Also if you open IIS->Url Rewrite and go to your rule you will see there is a option to test rule, you can simply paste your url and have an overview how URL is parsed. You will then also realize which part you can use to append query string.
http://www.iis.net/learn/extensions/url-rewrite-module/testing-rewrite-rule-patterns
I'm trying to create a rewrite rule in IIS 7.5 Url Rewrite. What I'm trying to achieve is when someone clicks on a certain pdf file, I want them to be redirected to a form and then when they've filled out the form they get the pdf file which simply has a question mark.
e.g. ?download=true appended to the end of it that passes through the rewrite rule so:
pdf/my-pdf-file.pdf will be redirected to go-to-this-file.aspx (which would be a form)
then they're redirected to :
pdf/my-pdfpfile.pdf?download=true which the rewrite rule shouldn't pick up but it does which is my problem.
Here is my rule:
<system.webServer>
<rewrite>
<rules>
<rule name="My PDF Rule">
<match url="^pdf/my-pdf-file.pdf$" ignoreCase="true" />
<action type="Rewrite" url="/go-to-this-file.aspx" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
Please can someone help. Cheers!
The problem is simple, you should check if the {QUERY_STRING} contains download=true and then don't redirect. Try this:
<system.webServer>
<rewrite>
<rules>
<rule name="My PDF Rule">
<match url="^pdf/my-pdf-file.pdf$" ignoreCase="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="download=true" negate="true" />
</conditions>
<action type="Rewrite" url="/go-to-this-file.aspx" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
I have read the threads and I still can't work it out, my problem I know, but wondering if could point me in the right direction.
I have setup a rule:
www.mydomain.com/productlist.asp?CategoryID=2
rewritten to
www.mydomain.com/homeware/cushions
.
<rule name="cushions">
<match url="^homeware/cushions" />
<action type="Rewrite" url="productlist.asp?CategoryID=2" />
</rule>
ok, now my problem is with pagination of the results, so the original domain when the user goes onto the next page would look like:
www.mydomain.com/productlist.asp?CategoryID=2&Page=2
This is where I'm having problems - I want this to become:
www.mydomain.com/homeware/cushions?page=2
and ongoing for how many pages
just can't get it to work - I understand I need to use query string but really struggling. Asking for expertise, thanks for any help
To capture the Query String you need to use conditions for that since the match URL does not include it.
So you could do that with a rule like:
<rule name="cushions" stopProcessing="true">
<match url="^homeware/cushions$" />
<conditions>
<add input="{QUERY_STRING}" pattern="page=(\d+)" />
</conditions>
<action type="Rewrite" url="productlist.asp?CategoryID=2&page={C:1}" appendQueryString="false" />
Just add appendQueryString="true" in action will automatically append query string.
<rewrite>
<rules>
<rule name="test">
<match url="^homeware/cushions" />
<action type="Rewrite" url="/test/test.cfm?category=5" appendQueryString="true" />
<conditions>
</conditions>
</rule>
</rules>
</rewrite>
http://localhost:8081/homeware/cushions?page=2
You will receive page in URL variable with value 2.