I'm trying to setup rewrite for url from /place/search-the-places/item-detail/id=123 to /place/explore-our-places/item-detail/id=123
but it doesn't work, what I'm doing wrong?
<rewrite>
<rules>
<rule name="Collections" stopProcessing="true">
<match url="^place/search-the-places/item-detail/id=([0-9]+)" ignoreCase="true" />
<action type="Redirect" url="/place/explore-our-places/item-detail/?id={R:1}" />
<conditions>
</conditions>
</rule>
</rules>
</rewrite>
Thanks!
If you just want to match numeric id as a parameter, then instead of
id=([0-9]+)/([_0-9a-z-]+)
use
id=([0-9]+)
because the slash between regexes means your route is like this
/place/search-the-places/item-detail/id=123/end-of-route
and this is not true, I suppose.
Also try using type="Rewrite" instead of "Redirect".
Related
The standard web.config rewrite to turn all HTTP into HTTPS works fine
<rewrite>
<rules>
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
redirectType="Temporary" />
</rule>
</rules>
</rewrite>
URLS that begin with HTTP://192.168 should not be rewritten but I've been unable to change the code to do this. I've tried to change the match to HTTP://192.168 and then negate it but I think that affects the action line
I have a project in asp net core 2.0.
I Have stablished the next Rule in the web.config:
<rewrite>
<rules>
<rule name="wwwroot" >
<match url="([\S]+[.](js|css|png|gif|jpg|jpeg))" />
<action type="Rewrite" url="wwwroot/{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
When i acces to the url: www.foobar.com/lib/chart.js/dist/Chart.js for some reason the iis try to finde Chart.js in the path: wwwroot/lib/chart.js ignoring the last part of the url (/dist/Chart.js) when im expecting to take wwwroot/lib/chart.js/dist/Chart.js
Try to modify your regexp like this: ([\S]+[.](js|css|png|gif|jpg|jpeg))$ it should consider file extension if they at the end of your url
EDIT
To your rule you should exclude urls starting from wwwroot
<rule name="wwwroot" >
<match url="([\S]+[.](js|css|png|gif|jpg|jpeg))" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" negate="true" pattern="^/wwwroot" ignoreCase="true" />
</conditions>
<action type="Redirect" url="wwwroot/{R:1}" logRewrittenUrl="true" />
</rule>
I posted a question up yesterday basically I have a single plan with winhost and I want to be able to have multiple domains (that are all pointed at my root) go to different subfolders and in these sub-folders I host different MVC apps. A very helpful chap took me most of the way but (and I know its lame how difficult im finding this) but I really cannot work out how to do the final peice...
The IIS config...
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect if producerpte" stopProcessing="true">
<match url="^producerpte/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Rewrite to sub folder">
<match url="^.*$" />
<action type="Rewrite" url="producerpte/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
works brilliantly. When I now go to http://www.producerpte.co.uk I can see my site in the subfolder but the url looks like its on the root. However I also want to try and host my girlfriends site so I have tried multiple combinations but I just cannot seem to add rules that will work for both sites...I know I need to add two more rules like this...
<configuration>
<system.webServer>
<rewrite>
<rules><!--first site-->
<rule name="Redirect if producerpte" stopProcessing="true">
<match url="^producerpte/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Rewrite to sub folder producerpte">
<match url="^.*$" />
<action type="Rewrite" url="producerpte/{R:0}" />
</rule>
<!--second site-->
<rule name="Redirect if samyoga" stopProcessing="true">
<match url="^samyoga/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Rewrite to sub folder samyoga">
<match url="^.*$" />
<action type="Rewrite" url="samyoga/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Whatever it is about the last rule I just cant get it to route. If I use it then when I go to Samyoga.co.uk I end up at Samyoga.co.uk/producerpte ?????
I tried matching the wildcard in the second rule (for each site) it just doesnt work at all then.....
How do you get filenotonserver.html to show up in a browser? and not 404 error. How can I do a URL rewrite to match .html to default2.aspx, or vice versa??
Do this make any sense? I am newbie on URL rewrite for sure...
k, been looking around:
<rewrite>
<rules>
<rule name="SpecificRedirect" stopProcessing="true">
<match url="^page$" />
<action type="Redirect" url="/page.html" />
</rule>
</rules>
</rewrite>
In the "match url" trying to match .html and action type would be default.aspx?p=whatevetmatched.html
Any ideas please?
ok so I got it:
<rewrite>
<rules>
<rule name="Redirect">
<match url="(.*)\.html$" />
<action type="Rewrite" url="default2.aspx?p={R:1}" />
</rule>
</rules>
</rewrite>
And on the default2.aspx reads the request("p") which has the "matched" html name and I then look it up in the database to display the data for that matched html "page"
I want to all www domain to naked via IIS Rewrite engine. There are many domains pointing to same application.
Here is my rule :
^(www.)(.*)$
Action Type : Redirect
Redirect URL : {R:2}
Redirect Type : Permanent
When i test pattern for www.xxx.com
R:0 => www.stackoverflow.com R:1=> www. R:2 => www.stackoverflow.com
and that is fine.
What is wrong? And also should I include "http://" ?
Something like ^(www\.)(.+)$ should work when matching the http_host, but it might be better to specify the domain. From what I know of IIS (not much) and what it says on the net, something like:
<rewrite>
<rules>
<rule name="Redirect www.xxx.com to xxx.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.domain\.com$" />
</conditions>
<action type="Redirect" url="http://domain.com/{R:0}" />
</rule>
</rules>
</rewrite>
Oh, you said for any domain. If you want to make sure it ends in .com it should be something like
^(www\.)(.+)(\.com)$ against HTTP_HOST
.. oh, if you do that you need to back reference, so try something like this:
<rewrite>
<rules>
<rule name="Redirect www.domain.com to domain.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
The c:1 is a back reference