I have the following rule in my webconfig
<rule name="accommidationRewrite2" enabled="true" stopProcessing="true">
<match url="accommodation/(?!results|!property).*?(.*)/" />
<action type="Rewrite" url="/index.cfm/?path=/accommodation/results/params/location/{R:1}/" />
</rule>
I'm trying to get the rule to kick in is the URL is not 'accommodation/results/....' OR 'accommodation/property/.....'
At the moment it only work for the results URL. Can I get it to work for both URL's?
Remove the ! symbol which was present before the property ,
accommodation/(?!results|property).*?(.*)/
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 :)
This is a Azure WebApp web.config question.
I want to redirect all non-HTTPS requests to same url but with HTTPS, basically replacing the HTTP with HTTPS.
But not if the url containst following string: "/config/add_new_user?login=xxx&w=1".
This is my block in the section in web-config.
<rule name="Force HTTPS" stopProcessing="true">
<match url="(\/config\/add_new_user\?login=license_wizard\&w=1)" negate="true" />
<conditions>
<add input="{HTTPS}" pattern="OFF" />
</conditions>
<action type="Rewrite" url="public/redirect.html" />
</rule>
But i get error 500.19 - Configuration file is not well-formed XML
I used https://regex101.com/#javascript to work out the regex and tested with different urls. It seams to work out, the expression hits on the text.
So the negate="true" should reverse the statement, so only urls without the given string is matched and thus rewritten.
Oh by the way, the web.config xml seams to be ok, because when i change the regex back to the original then web-site works.
So this works:
<match url="(.*)" />
and this does not:
<match url="(\/config\/add_new_user\?login=license_wizard\&w=1)" negate="true" />
The & must be encoded as & in XML files.
<match url="(\/config\/add_new_user\?login=license_wizard\&w=1)" negate="true" />
<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 have a pool of applications that I want to run under a ARR server that should serve as a router for all my applications.
I have defined a set of rules that should be applied in waterfall, but something is not working the proper way.
The first rule should handle the trailing slashes, the other rules should map my applications to resolve for my internal DNS server with rewrite URL, but the problem seems to happen during the first rule.
The default behaviour is that, if I try to launch my application with http://myapp will return 404 code, if I try to run it by adding the slash (http://www.myapp/ ) everything works fine. So basically my rule should check for URL patterns without the slash: if the resource is a directory it should add the slash at the end of the Url.
So the pattern to catch the url is the following regular expression:
.*[^/]$
This should catch url without / at the end and I successfully tested it.
For every url that matches the regexp, I should check if it's a directory, and in the case I should set the trailing slash, so:
{REQUEST_FILE} -> Is a directory
But this doesn't work. I also tried to add the following rule with no success:
{REQUEST_FILE} -> Is not a file
The rule to apply is the following:
Redirect to (rewrite leads to same behaviour, too):
{R:O}/
It seems not to add the / to my urls and I don't know how to check which steps fail to succeed. The next rules basically follow this pattern:
mywebapp/* redirect to www.mydnsappaddress/{R:1}
EDIT: I add the web.config sample to show you the textual version of the rules.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Trailing Slash" enabled="false" stopProcessing="true">
<match url=".*[^/]$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
</conditions>
<action type="Redirect" url="{R:0}/" />
</rule>
<rule name="app1" enabled="false" patternSyntax="Wildcard">
<match url="sites/doc/*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://mypersonaldnsaddress/{R:0}" />
</rule>
<rule name="ASTCO portale NWS" enabled="true" patternSyntax="Wildcard">
<match url="portale/*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://mypersonaldnsaddress/{R:0/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I have to ask the obvious: does your example deliberately have enabled set to false?
I was able to make this work exactly as you desire: if the directory exists, add a slash at the end, if it doesn't, don't.
<rule name="Trailing Slash" enabled="true" stopProcessing="true">
<match url=".*[^/]$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
</conditions>
<action type="Redirect" url="{R:0}/" />
</rule>
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.