<rule name="WomensSilverBangles" patternSyntax="ExactMatch">
<match url="/Bangles/Silver/Womens.aspx" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="Collections/jewellery.aspx?AXSW_CategoryID=Bangles&AXSWFinenessId=Silver&AXSW_GenderID=Womens&MenuName=Jewellery&SiteMapNode=Silver Bangles&depth=2" />
</rule>
Can this be written using wildcards?
As you can see, the three variables in the match URL are used in the rewritten URL string.
I know it's been a while since this question was posted, but there is an excellent article on rewriting here and based on that, you could try experimenting with something like this(not tested):
<rule name="3levelcatchall" patternSyntax="Wildcard">
<match url="/*/*/*.aspx"/>
<action type="Rewrite" url="Collections/jewellery.aspx?AXSW_CategoryID={R:1}&AXSWFinenessId={R:2}&AXSW_GenderID={R:3}&MenuName=Jewellery&SiteMapNode={R:2} {R:1}&depth=2" appendQueryString="false"/>
</rule>
Related
I need to extract all the vanity URLs redirect rules but exclude the redirect rules.
<rule name="welcome2020" stopProcessing="true">
<match url="welcome2020" />
<action type="Redirect" url="https://www.mywebsite.org/Pages/.welcome2020aspx" appendQueryString="false" />
</rule>
<rule name="Page to Page Redirect">
<match url="/Staff/Pages/Ashley.aspx" />
<action type="Rewrite" url="services/Staff/Pages/Ashley.aspx" />
</rule>
i need to match all <match url="whatever" /> types that don't contain .aspx The only thing I have figured out is that I will need a negative lookahead. but not sure how to implement it.
I basically need something like this, but for my redirect rules.
https://www.regextester.com/15
You can just try:
^(?=.*match)(?!.*\.aspx).*
Please see the DEMO :)
I like to use Umbraco with Vue.js and leave all the routing to Vue so I can make SPA. My goal is to write an IIS rewrite rule in web.config for using one Umbraco template for all routes except /umbraco. So far I have this
<rewrite>
<rules>
<rule name="Startview Templating">
<match url="^(http(s)?:\/\/)?(www\.)?([A-Za-z0-9:._-]*)(\/(?!umbraco)([A-Za-z0-9:_-]*))?" />
<action type="Rewrite" url="{R:0}?alttemplate=test" appendQueryString="true"/>
</rule>
</rules>
</rewrite>
This renders the same template (test)on every route I have so that works. But when I enter /umbraco I get a blank page. What am I missing?
Thanks
You should be able to add conditions to the rule to exclude paths, for example:
<conditions>
<add input="{REQUEST_URI}" pattern="^/umbraco/" negate="true" />
</conditions>
In your case i would look something like (I think you can simplify the match url though):
<rewrite>
<rules>
<rule name="Startview Templating">
<match url="^(http(s)?:\/\/)?(www\.)?([A-Za-z0-9:._-]*)(\/(?!umbraco)([A-Za-z0-9:_-]*))?" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/umbraco/" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}?alttemplate=test" appendQueryString="true"/>
</rule>
</rules>
</rewrite>
<rule name="Posts2" enabled="true">
<match url="^index.cfm\?section=latest.news&id=(.*)" />
<action type="Rewrite" url="post.php?id={R:1}" />
</rule>
Problem is with the regex - any idea at all? I can't seem to work it out. I've run it on http://www.xmlvalidation.com/ and it says
The reference to entity "id" must end with the ';' delimiter.
When I change the ampersand to & the rewrite doesn't seem to work on URLs such as /index.cfm?section=latest.news&id=14726 despite it passing the test in IIS. Even when I escape the dots and question mark it doesn't work
Try using a {QUERY_STRING} input using conditions perhaps:
<rule name="Posts2">
<match url="index\.cfm$" />
<conditions>
<add input="{QUERY_STRING}" pattern="section=(latest\.news)" />
<add input="#{C:1}#_{QUERY_STRING}" pattern="#([^#]+)#_.*id=(\d+)" />
</conditions>
<action type="rewrite" url="post.php?id={C:2}" appendQueryString="false"/>
</rule>
URL's containing query strings are usually better handled this way, although if you really prefer not going this route then make sure you have the all the proper tags included, and also try escaping the . in between latest\.news.
<rewrite>
<rules>
<rule name="Posts2">
<match url="^index\.cfm\?section=latest\.news&id=(\d+)" />
<action type="Rewrite" url="post.php?id={R:1}" />
</rule>
</rules>
</rewrite>
I am new to .NET and IIS ans I am trying do a regular expression redirect with this pattern \/([^\/]+)(?=\/[^\/]+\/?$) so my url wil go from mysite.com/en/solutions/exemple to mysite.com/en/exemple but in the redirection IIS put /Service in my URL someone as a idea how to fix this?
here is the rule generated in my web.config by IIS 7
<rewrite>
<rules>
<rule name="redirect salesforce" stopProcessing="true">
<match url="\/([^\/]+)(?=\/[^\/]+\/?$)" />
<action type="Redirect" url="/en/{R:0}/coveo-for-salesforce" appendQueryString="false" />
</rule>
</rules>
</rewrite>
Thanks
UPDATE:I tried
<rewrite>
<rules>
<rule name="remove solutions from url" stopProcessing="true">
<match url="^([^/]+)(/[^/]+)(/.*)" />
<action type="Redirect" url="/{R:0}{R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
I get a not not found
Please note that I am working on a Sitecore solution with 2 languages en and fr
If you want to remove the first level folder from the url, e.g.:
/en/solutions/example-page -> /en/example-page
/en/other-folder/another-page -> /en/another-page
/fr/one-more-folder/blah-page -> /fr/blah-page
with the 301 redirect code, use the following rule:
<rewrite>
<rules>
<rule name="remove solutions from url" stopProcessing="true">
<match url="^([^/]+)(/[^/]+)(/.*)" />
<action type="Redirect" url="/{R:1}{R:3}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
If you want to redirect with 301 code from mysite.com/en/solutions/exemple to mysite.com/en/exemple (so in fact remove solutions from all urls (but only if they are directly after language), you can use:
<rewrite>
<rules>
<rule name="remove solutions from url" stopProcessing="true">
<match url="^([^/]+)/solutions(/.*)" />
<action type="Redirect" url="/{R:1}{R:2}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
I've tested the solution on Sitecore application and it definitely works.
On my iis7 box, I have a url rewrite rule in my web.config that keeps all of my urls lowercase:
<rule name="LowerCaseRule1" stopProcessing="false">
<match url="^((?=.*[A-Z]).*\.aspx)(.*)" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:1}}{R:2}" />
</rule>
This has been working well, but it also rewrites my AJAX WebMethod calls when they contain any capitals letters. Consequently the methods don't get called. An obvious solution is to keep all WebMethods lowercase, but it would be way more appropriate to attack it on the front from the rewrite's regex.
Currently:
/Default.aspx ==> /default.aspx
/Default.aspx/UpdateOrder ==> /default.aspx/updateorder
I'd like the latter example to rewrite to /default.aspx/UpdateOrder
My regex skills just can't get me there.
Thanks in advance,
John
I set this problem aside and came back to it much later. I added a negate condition and it seems to do the trick:
<rule name="LowerCaseRule1" stopProcessing="false">
<match url="^((?=.*[A-Z]).*\.aspx)(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_URL}" matchType="Pattern" pattern="^([^A-Z]+\.aspx/)(.*)" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" url="{ToLower:{R:1}}{R:2}" />
</rule>