I have a rewrite pattern that I can't get to work.
if someone goes to my site by using this url:
http://example.com/article/page/1?_escaped_fragment_=
I would like my rewrite pattern to match the querystring and then rewrite my path to
/snapshots/snapshot_article_page_1.html
I tried writing a rule like this:
<rule name="Seo rewrite rule" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" />
</conditions>
<action type="Rewrite" url="/assets/snapshots/snapshot__{REQUEST_URI}.html" appendQueryString="false" />
</rule>
But I just keep getting a 404 error (even though the page exists!). I even tried actually putting in the full URL to the page and it doesn't work, but if I put the URL in the browser, it shows it fine.
It appears I have done it.
The rule to match my example would be this:
<rule name="Seo rewrite rule" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" />
</conditions>
<action type="Rewrite" url="/assets/snapshots/snapshot__{R:0}.html" appendQueryString="false" />
</rule>
Related
I'm using Asp.Net web forms.In my URL I don't want to expose after the character '?'. I want the regular expression pattern to achieve this using IIS 10. I have tried this "Security(.+)$" but it doesn't work.
From this: www.some.com/Security/login.aspx?name=dfdf
To this: www.some.com/Security/login.aspx
If you don't want to expose query string.
1.you should redirect any request to www.some.com/Security/login.aspx?name=dfdf to www.some.com/Security/login.aspx.
2.Then you have to rewrite request from www.some.com/Security/login.aspx back to www.some.com/Security/login.aspx?name=dfdf
Just keep in mind that, this rule can only rewrite back to static query string ?name=dfdf.
If you need to need to dynamic rewrite the URL, then you may need to add a custom request header to save the query string. So that backend server will know where should it rewrite back.
<rules>
<rule name="redirect rule" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/Security/login.aspx\?(.+)" />
</conditions>
<action type="Redirect" url="Security/login.aspx" appendQueryString="false" redirectType="Temporary" />
</rule>
<rule name="rewrite back" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/Security/login.aspx$" />
</conditions>
<action type="Rewrite" url="Security/login.asp?name=dfdf" appendQueryString="false" />
</rule>
</rules>
I have a site that uses two characters in the URL path to determine the initial language e.g. https://my.company.net/Monitoring/gb displays in the English language. I want to setup a redirect for these two display the full culture code e.g. https://my.company.net/Monitoring/en-GB
This is the rule that I've tried:
<rewrite>
<rules>
<rule name="Monitoring gb rewrite" patternSyntax="ExactMatch" stopProcessing="true">
<match url="https://my.company.net/Monitoring/gb" />
<conditions />
<serverVariables />
<action type="Redirect" url="https://my.company.net/Monitoring/en-GB" appendQueryString="false" />
</rule>
</rules>
</rewrite>
I expected https://my.company.net/Monitoring/gb to redirect to https://my.company.net/Monitoring/en-GB however this rule does not have any effect: the browser URL stays at https://my.company.net/Monitoring/gb.
How can I rectify this?
You could use below url rewrite rule.
<rule name="gb to en-gb redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="ww.sample1.com" />
<add input="{HTTPS}" pattern="on" />
<add input="{REQUEST_URI}" pattern="Monitoring/gb" />
</conditions>
<action type="Redirect" url="https://www.sample1.com/Monitoring/en-GB" />
</rule>
Note: use your hostname instead of the www.sample1.com.
The redirect failure was due to browser caching. The redirect works once the cache is cleared.
I am trying to add redirect rule 'www' when the request comes without the 'www' for the site. ie. http://example.com to http://www.example.com
Here is what the rule looks like:
<rewrite>
<rules>
<rule name="Add www" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="example.com" />
</conditions>
<action type="Redirect" url="http://www.example.com" />
</rule>
</rules>
</rewrite>
Once i add this rule, the site goes to infinite loop and it just error out (page can't be displayed error message). The server is brand new and it might be missing some redirect components (if there is one). I did install URL Rewrite component and added rule in it.
Any suggestions?
Thanks.
You have not chosen a pattern syntax and so you using the default regular expression syntax. As a result your pattern matches both example.com and www.example.com and causes an infinite loop. Try this:
<rewrite>
<rules>
<rule name="Add www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="example.com" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" />
</rule>
</rules>
</rewrite>
Why isn't this rule working when I go to a browser with the URL rewrite module?
It works on the regex tester with the url rewrite module.
I even put it at the top of all my rules.
Example url: organizations/51/middle-tennessee-basketball-showcases-basketball-tournaments?page=1
Rewrite rule:
<rule name="Organization Redirect" stopProcessing="true">
<match url="^organizations/(.*)-basketball-tournaments\?page=1$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="organizations/{R:1}" appendQueryString="false" />
</rule>
Your rule should be as following:
<rule name="Organization Redirect" stopProcessing="true">
<match url="^organizations/(.*)-basketball-tournaments$" />
<conditions>
<add input="{QUERY_STRING}" pattern="^page=1$" />
</conditions>
<action type="Redirect" url="organizations/{R:1}" appendQueryString="false" />
</rule>
You should not check the query string (here page=1) in the url test but in the conditions section.
I would like to match exactly https://internet.dev.local/KYR url (without / into end) and redirect or rewrite to https://internet.dev.local/KYR/ (with /).
I am trying the following rule but it matches other URLs as well e.g. https://internet.dev.local/KYR/Admin/Form/Default.aspx?signup=false, which is wrong.
so how can I achieve this?
<rule name="Static redirect" patternSyntax="ExactMatch" stopProcessing="true">
<match url="https://internet.dev.local/KYR" negate="true" />
<conditions>
</conditions>
<action type="Redirect" url="/Login/?ReturnUrl=/Member/KYR/" redirectType="Permanent" />
</rule>
If you need to test the host and protocol you have to put it in the conditions, not in the global rule.
Following your example, it would be as follow:
<rule name="test" patternSyntax="ExactMatch" stopProcessing="true">
<match url="KYR" />
<action type="Redirect" url="/KYR/" redirectType="Permanent" />
<conditions>
<add input="{HTTP_HOST}" pattern="internet.dev.local" />
<add input="{HTTPS}" pattern="on" />
</conditions>
</rule>
I have changed the url in the action because your question says:
redirect or rewrite to https://internet.dev.local/KYR/ (with /).
EDIT:
To get it to work on any host (with or without SSL), just remove the conditions:
<rule name="test" patternSyntax="ExactMatch" stopProcessing="true">
<match url="KYR" />
<action type="Redirect" url="/KYR/" redirectType="Permanent" />
</rule>