Tuckey URL: Redirected url is outputted twice - url-rewriting

I have the following redirect in place:
<rule>
<condition name="host" operator="equal">^(www.)?test.redirect.com$</condition>
<from>^?</from>
<to type="redirect" last="true" encode="true">http://www.redirect.com/test/test-123</to>
</rule>
It does redirect, however it redirects to http://www.redirect.com/test/test-123http://www.redirect.com/test/test-123. Does anyone know why it is outputting twice like that?
As a side note I want to add that it is NOT being redirected twice.

The <from> clause was incorrect:
<rule>
<condition name="host" operator="equal">^(www.)?test.redirect.com$</condition>
<from>^(.*)</from>
<to type="redirect" last="true" encode="true">http://www.redirect.com/test/test-123</to>
</rule>

Related

url rewrite rule to parse url dynamically

I am using rewrite map method to achive my seo friendly urls.
<rewriteMaps>
<rewriteMap name="Destinations">
<add key="/point-a-to-point-b" value="/destination-final.asp?from=point%20a&to=point%20b" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Rewrite rule1 for Destinations">
<match url=".*" />
<conditions>
<add input="{Destinations:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
My problem is I have too many destinations and having to write a map for each results in 500 error. I believe there is a limit to the number of maps you can have on single web.config file.
would it be possible to achive this using a wildcard rule?
that would parse the url and use the bit before "to" as starting point and the bit after "to" as end point and send it to the file as querystring?
for example
/newyork-to-texas
would send the following querystring:
from=newyork&to=texas
Could you please share a detailed error message for 500 error. if you want to achieve your requirement /newyork-to-texas to from=newyork&to=texas you could use below url rewrite rule:
<rule name="send value to query string" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="(.*)/(.*)\-to\-(.*)" />
</conditions>
<action type="Redirect" url="http://localhost:746/default.aspx?from={C:2}&to={C:3}" appendQueryString="false" />
</rule>
Regards,
Jalpa.

IISRewrite encoding of %2f in path

So I have a path like this (I am using webforms):
folder/first/second/
which has the following rewrite rule behind it
<rule name="firstLevel">
<match url="^folder/([^/]+)/([^/]+)/?$" />
<action type="Rewrite" url="firstSecond.aspx?param1={R:1}&param2={UrlEncode:{R:2}}" />
</rule>
my issue is when I try and pass the following:
folder/first/sec%2fond/ (I want R2 to be sec%2fond where I will urlDecode it back to the page. for a result like "sec/ond".
However my rule keeps taking it as though I want
folder/first/sec/ond
Requested URL
http://localhost:85/research/first/sec/ond/
Physical Path
\rewritetest\folder\first\sec\ond\
Thanks for any assists..
I found a working solution to this issue for anyone else.
<rule name="secondLevel">
<match url="^folder/(.+)/(.+)/?$" ignoreCase="true" />
<action type="Rewrite" url="firstsecond.aspx?param1={C:1}&param2={C:2}" />
<conditions>
<add input="{UNENCODED_URL}" pattern="/folder/([^/]+)/([^/]+)/?$" />
</conditions>
</rule>

URL Rewrite troubleshoot

We have our URL rewrite as followed. I tested the pattern in IIS 8.5 URL Rewrite and the patterns matched as what we wanted. However, it's 404 every single time. Will someone take a look and see what is wrong with my URL rewrite? Thank you.
URL: devbox.mysite.com/article/how-to-use-onedrive
Pattern: (.*)/article/(.*)$
Action Rewrite URL: {R:1}/article/?artID={R:2}
Currently the page shows 404. Below is the XML code in web.config file.
<rule name="Article-rewrite" enabled="true">
<match url="(.*)/article/(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="{R:1}/article/?artID={R:2}" appendQueryString="false" />
</rule>
Try this:
<rule name="Article-rewrite" enabled="true">
<match url="article/(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="article/?artID={R:1}" appendQueryString="false" />
</rule>
I've removed the domain from the match url, as you're not switching the domain.

URL Rewrite with query parameter is not working

The following url-rewirte rule is not working,
<rule>
<from>^/coupon.do\?cc=([A-Z]{4})$</from>
<to last="true">/services/1.0/coupon/$1</to>
</rule>
redirect from /coupon.do?cc=ABCD to /services/1.0/coupon/ABCD is not working.
Please let me know my mistake.
Default type for <to> is forward, that said for redirect you have to change it explicitly to have type="redirect".
However, to have URL matched to your pattern, you need to add use-query-string="true" to your <urlrewrite> opening tag. So this should work,
<urlrewrite use-query-string="true">
<rule match-type="regex">
<from>^/coupon.do\?cc=([A-Z]{4})$</from>
<to type="redirect" last="true">/services/1.0/coupon/$1</to>
</rule>
</urlrewrite>
And don't forget to have match-type="regexp" for your rule.

How do I ignore the .aspx extension when using a rewrite map?

I have a rewrite map with ~100 old URL to new URL rows:
<rewriteMaps>
<rewriteMap name="OldSiteRewriteMap" defaultValue="">
...
<add key="/a/b/oldpage" value="/x/y/newpage" />
...
</rewriteMap>
</rewriteMaps>
I have a rewrite rule that uses that map to redirect URL's (we've just launched a new website and we're mapping the URL's from the old site to the corresponding URL on the new site):
<rule name="Redirect old site URLs">
<match url=".*" />
<conditions>
<add input="{OldSiteRewriteMap:{PATH_INFO}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" redirectType="Permanent" appendQueryString="false" />
</rule>
When I visit http://example.com/a/b/oldpage (the old site URL) I get redirected to http://example.com/x/y/newpage - great! But when I visit http://example.com/a/b/oldpage.aspx -note the .aspx extension - I don't get redirected.
How can I tell my rewrite rule to ignore the ".aspx" extension when it's trying to map URL's using the rewrite map?
A coworker suggested the following - using a regex in the "match url" to capture everything except a possible trailing ".aspx" and then passing the capture to the rewrite map in lieu of PATH_INFO or any of the other server vars. Seems to work pretty well.
<rule name="Redirect old site URLs">
<match url="^(.+?)(\.aspx)?$" />
<conditions>
<add input="{OldSiteRewriteMap:{R:1}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" redirectType="Permanent" appendQueryString="false" />
</rule>

Resources