I have the following problem:
i want to let the users of an exact url redirect to another one.
Note: my URL immediately downloads a file.
What i want is to let the file forward to another file (it needs to download the file i'm redirecting to).
My Rule:
<rule name="File" patternSyntax="ExactMatch" stopProcessing="true">
<match url="https://SITE.be/download/DownloadFile?id=138999" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="https://SITE.be/download/DownloadFile?id=138999" />
<add input="{QUERY_STRING}" pattern="https://SITE.be/download/DownloadFile?id=138999" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
</conditions>
<action type="Redirect" url="https://SITE.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
my rule isn't working, it doesn't redirect it and when i check 'URL redirect checkers' it mentions that there isn't a redirect set on the URL.
what am i doing wrong?
Edit:
I tried:
<rule name="File" stopProcessing="true">
<match url="download/DownloadFile?id=138999" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^site.be$" />
</conditions>
<action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
with no improving (redirect checkers on google still don't trigger that theres a redirect set)
According to your iis rewirte code, I find it has problem in match url part.
This part could only match the [download/DownloadFile] not the querystring.
If we want to check the query string id, we should use url rewrite condition.
More details, you could refer to below url rewrite rule.
<rule name="File" stopProcessing="true">
<match url="download/DownloadFile" />
<conditions logicalGrouping="MatchAll">
<add input="{QUERY_STRING}" pattern="id=138999" />
<add input="{HTTP_HOST}" pattern="^site.be$" />
</conditions>
<action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
Or
<rule name="File" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="sitebe" />
<add input="{REQUEST_URI}" pattern="download/DownloadFile\?id=138999" />
</conditions>
<action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
Related
i need to rewrite the url from old page to new page, an example:
old: https://www.mysite.it/scheda.asp?num=123456
new: https://www.mysite.it/scheda/?num=123456
i've put in web.config the following lines but don't work, when i go to https://www.mysite.it/scheda.asp?num=123456 noting happen, site go to the page without rewrite:
<rule name="scheda-rew" stopProcessing="true">
<match url="scheda.asp(.*)" />
<action type="Rewrite" url="scheda/{R:1}" logRewrittenUrl="true" />
</rule>
i try this:
<rule name="scheda-rew2" stopProcessing="true">
<match url="^scheda\.asp" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="isbn=([0-9]+)" />
</conditions>
<action type="Redirect" url="scheda/{C:1}" appendQueryString="false" />
</rule>
nothing appen, seem that all change i do haven't effect
You can try below rule, if you have any question please let me know:
<rule name="RewriteUserFriendlyURL2" stopProcessing="true">
<match url="^scheda.asp\?([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^scheda/$" negate="true" />
</conditions>
<action type="Redirect" url="scheda/?num=123456" appendQueryString="false" />
</rule>
I'm trying to wrap my head around this problem;
I have a default site with an application that resides in a subfolder, e.g. /app/app.html
It also accepts a language parameter, so for example http://192.168.0.1/app/app.html?language=fi would work.
Now I have two subdomains that I need to not only get rewritten to the correct folder, but also include the language parameter. For example:
fi.domain.com -> http://1.1.1.1/app/app.html?language=fi
swe.domain.com -> http://1.1.1.1/app/app.html?language=swe
I've made A records for both subdomains to point to 1.1.1.1
Currently there are no special bindings (only port 80, no hostnames and all IPs) and no special default pages.
EDIT: I've tried using the URL rewriter module, but I haven't been able to get it work as intended.
EDIT 2: My first example of how I need it to work was a bit flawed, here's a better version;
finnishword.domain.com -> http://1.1.1.1/app/app.html?language=fi
otherwordinswedish.domain.com -> http://1.1.1.1/app/app.html?language=swe
I'm not sure to well understand your question.
It seems that you need URL rewriting rules.
According to this link
<rule name="CName to URL - Rewrite" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(.*)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language={C:1}" />
</rule>
I think it's what you need ;)
Edit 24/08/2016
If you can't have a dynmique pattern with RegEx you have to do as many rules as you have subdomains:
<rule name="finnishRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(finnishword)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language=fi" />
</rule>
<rule name="finnishRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(otherwordinswedish)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language=swe" />
</rule>
or you can mixup all together if you want to redirect all subdomains that contains the word "swedish" on url with ?
<rule name="finnishRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(.*swedish.*)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language=swe" />
</rule>
So after all the RegEx pattern is up to you ;)
Edit 25/08/2016
Maybe you have to add condition to skip static files
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
...
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<rules>
<clear />
<rule name="swedishMainRule" enabled="true" stopProcessing="true">
<match url="^$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?swedishword\.domain\.fi$" />
<add input="{QUERY_STRING}" pattern="language=" negate="true" />
</conditions>
<action type="Redirect" url="?language=sve" appendQueryString="false" logRewrittenUrl="false" />
</rule>
<rule name="swedishRule" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?swedishword\.domain\.fi$" />
</conditions>
<action type="Rewrite" url="/app/{R:1}" />
</rule>
<rule name="finnishRule" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?anotherfinnishword\.domain\.fi$" />
</conditions>
<action type="Rewrite" url="/app/{R:1}" />
</rule>
</rules>
This is how I ended up doing it, basically the first rule deal with the language parameter, and the other rules just rewrite the URL. The Finnish rule doesn't need an extra language rule since the default language of the app is Finnish.
I have installed URL rewrite module on the IIS 8.0 and configure rules
If user come without www and it will prefix www
If user comes from http then it will redirect to https
If user comes from mobile browser than it sends to mobile website
Below are the rules
<appcmd>
<CONFIG CONFIG.SECTION="system.webServer/rewrite/globalRules" path="MACHINE/WEBROOT/APPHOST" overrideMode="Inherit" locked="false">
<system.webServer-rewrite-globalRules>
<rule name="Mobile Redirect" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^$" ignoreCase="true" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_USER_AGENT}" pattern="android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos" />
<add input="{HTTP_X-Device-User-Agent}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-OperaMini-Phone-UA}" pattern="midp|mobile|phone" />
</conditions>
<serverVariables>
</serverVariables>
<action type="Redirect" url="/en-mobile" appendQueryString="false" />
</rule>
<rule name="Add HTTPS and WWW prefix to website.COM" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^website\.com" />
</conditions>
<serverVariables>
</serverVariables>
<action type="Redirect" url="https://www.website.com/{R:1}" appendQueryString="false" />
</rule>
<rule name="Add HTTPS to WWW.website.COM" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
</conditions>
<serverVariables>
</serverVariables>
<action type="Redirect" url="https://www.website.com/{R:1}" />
</rule>
</system.webServer-rewrite-globalRules>
</CONFIG>
</appcmd>
In above first rule Mobile redirect is done when user come from mobile browser. I redirect to https://www.website.com/en-mobile but when I do like this https://m.website.com/en-mobile it gives error but when I browse manually it works very good. So how can I redirect to that url when people come from https://www.website.com to https://m.website.com/en-mobile
I could solve this issue may be it will help to somebody so I am adding my solution over here. I change Mobile Redirect rule action to
<action type="Redirect" url="https://m.website.com/en-mobile" appendQueryString="true" redirectType="Found" />
Putting redirectType to found solves my issue.
I Have some problems with redirecting to another URL based on the query string parameters.
I have url for mapping service, for example "http://www.mydomain.com/?lon=111&lat=222&zoom=3"
and I need it to be redirected to "http://www.mydomain.com/111/222/3".
I have this rule in my web.config, but it does not work
<rule name="Location redirect">
<match url="\?lon=(\d+)&lat=(\d+)&zoom=(\d+)" />
<action type="Redirect" url="{R:1}/{R:2}/{R:3}" redirectType="Found" />
</rule>
The reason is that URL does not include Query String, you ned to use conditions for that. If you use the User Interface, it includes a friendly URL template that will generate it for you.
Below you will find the Rewrite rule as well as the redirect so that legacy traffic (ugly URL) is redirected to the pretty URL:
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^lon=([^=&]+)&lat=([^=&]+)&zoom=([^=&]+)$" />
</conditions>
<action type="Redirect" url="/{C:1}/{C:2}/{C:3}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^/([^/]+)/([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="?lon={R:1}&lat={R:2}&zoom={R:3}" />
</rule>
I Have some problems with redirecting to another URL based on the query string parameters. I want to redirect users which enter www.domain.com/signup.aspx?p=1 to:
www.domain.com/signup
<rule name="Signup Redirect 1" stopProcessing="true">
<match url="signup\.aspx\?p=1" />
<conditions logicalGrouping="MatchAll" />
<action type="Redirect" url="signup" redirectType="Temporary" />
</rule>
Now when they enter www.domain.com/signup.aspx?p=2 they must go to:
www.domain.com/signup/promocode
<rule name="Signup Redirect 2" stopProcessing="true">
<match url="signup\.aspx\?p=2" />
<conditions logicalGrouping="MatchAll" />
<action type="Redirect" url="signup/promocode" redirectType="Temporary" />
</rule>
The above rules don't work. What is the right way to do this? Thanks in Advance.
Gr
Martijn
A more robust method of using a value to select a destination is to use Rewrite Maps. The map is essentially a lookup table. This doesn't require a new rule (and an additional evaluation of the URL against a pattern on every request) for every new path.
<rules>
<rule name="Signup Redirect Map" stopProcessing="true">
<match url="^signup\.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="p=([^&]+)" />
<add input="{Signups:{C:1}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:2}" redirectType="Temporary" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="Signups">
<add key="1" value="signup" />
<add key="2" value="signup/promocode" />
<add key="3" value="signup/newcode" />
<add key="n" value="signup/futureproof" />
</rewriteMap>
</rewriteMaps>
Definitions:
{C:1} is a backreference to the first condition match: the query string value.
{Signups:{C:1}} is an instruction to look up {C:1} in the Signups map.
{C:2} is a backreference to the second condition match: the value from the Signups map.
See if this works a bit better:
<rule name="Signup Redirect 1" stopProcessing="true">
<match url="signup\.aspx$" />
<conditions>
<add input="{QUERY_STRING}" pattern="p=1" />
</conditions>
<action type="Redirect" url="signup" redirectType="Temporary" />
</rule>
<rule name="Signup Redirect 2" stopProcessing="true">
<match url="signup\.aspx$" />
<conditions>
<add input="{QUERY_STRING}" pattern="p=2" />
</conditions>
<action type="Redirect" url="signup/promocode" redirectType="Temporary" />
</rule>