I have the following URL rewrite setup inside web.config working as I would like.
<rule name="Product Rewrite" stopProcessing="true">
<match url="^products/([^$]+)/([^$]+)" />
<action type="Rewrite" url="products?durl={R:1}&purl={R:2}" />
</rule>
Now I need to exclude any URLs that contain or end with /action/edit i.e. products/action/edit
I understand that I will need a conditions block, but I am not sure what to write.
Any help would be greatly appreciated.
Add a condition like below, negate true ensures it matches everything except action/edit
<conditions>
<add input="{URL}" negate="true" pattern="action/edit" />
</conditions>
Related
I just need to create a rule in my web config file to rewrite all URLs to given into rule
ex:
url/services/presentations-evenementielles to
url/Services/Presentations-Evenementielles
This is all made for SEO purposes to avoid duplicates.
<rule name="ProductionRule2" stopProcessing="true" patternSyntax="ExactMatch" >
<match url="^/productions/xyz" ignoreCase="true" />
<action type="Redirect" url="Productions/XYZ" redirectType="Permanent"/>
</rule>
Above code its gives me infinite loop error.
There was some mistakes with your rule
1.You were trying to use "^" in an exact match rule. Please set it to regular expression
2.You are trying to use "/" in match url. The match url part of domain/productions/xyz is
productions/xyz instead of /production/xyz.
3.You are enabling ignore case when you redirect URL to itself.
So please try to modify the rule like this
<rule name="ProductionRule2" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^productions/xyz" ignoreCase="false" />
<action type="Redirect" url="Productions/XYZ" redirectType="Permanent" />
</rule>
Update:
Please modify the rule like this
<rule name="ProductionRule2" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^Productions/XYZ" ignoreCase="false" negate="true" />
<action type="Redirect" url="Productions/XYZ" redirectType="Permanent" />
<conditions>
<add input="{ToLower:{URL}}" pattern="/productions/xyz" />
</conditions>
</rule>
And this is working on my side
Please remember to clean browser cache when you test the rule.And the URL should be prODuctions/Xyz instead of prODuction/Xyz.
Here is my web.config rule
<rule name="spiderRedirect" stopProcessing="true">
<match url=".post/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z-]+)" />
<action type="Redirect" url="https://example.net/bot/post.php?category={toLower:{R:1}}&id={toLower:{R:2}}&title={toLower:{R:3}}" appendQueryString="false" />
</rule>
This should give this result
input:
https://example.net/post/celebrity/4cHYQ7i/maisie-williams
should result in:
{R1}: celebrity
{R2}: 4cHYQ7i
{R3}: maisie-williams
and it should redirect to:
https://example.net/bot/post.php?category=celebrity&id=4cHYQ7i&title=maisie-williams
This input:
https://example.net/post/nerdy/NE5cHQZ/when-i-have-to-do-technical-support
should result in:
{R1}: nerdy
{R2}: NE5cHQZ
{R3}: when-i-have-to-do-technical-support
The server runs and I am quite sure the regex is correct, but the rule is never triggered. I am never redirected to google, even if I use the above input.
Why isn't the rule triggered?
I got it working. Also with check for User agent.
I use this to redirect web crawlers.
<rule name="spiderRedirect" stopProcessing="true">
<match url=".?post/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z-]+)" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="(Google|MSNBot|Twitterbot|Pinterest|Facebot|facebookexternalhit|MJ12bot|bingbot|SimplePie|SiteLockSpider|okhttp|curl|YandexBot|ScoutJet|Slurp|DuckDuckBot|Baiduspider|Sogou|Konqueror|Exabot|ia_archiver|Screaming)"/>
<add input="{HTTPS}" pattern="on"/>
</conditions>
<action type="Redirect" url="https://example.net/bot/post.php?category={toLower:{R:1}}&id={toLower:{R:2}}&title={toLower:{R:3}}" appendQueryString="false" />
</rule>
You will escape "/" to matching your different input. The new regex is :
([0-9a-zA-Z]+)\/([0-9a-zA-Z]+)\/([0-9a-zA-Z-]+)
You can test it on https://regex101.com.
It match for your two different input.
I am working on a rewriting process. I have been stuck on a point that.
<rule name="Uk3" stopProcessing="true">
<match url="^activities/exploring/tours/tabid/3422/id/5205/k/([a-z0-9A-Z-\s]+)/p/1/nickis-beach-rides.aspx$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www.)?abc.co.uk$" />
</conditions>
<action type="Redirect" url="/activities/exploring/tours.aspx" />
</rule>
what does the above rule is doing:
It matches "activities/exploring/tours/tabid/3422/id/5205/k/" as it is and the it may contain anything after this upto "/p/1/nickis-beach-rides.aspx". It is working fine for all URLs except the following :
http://www.abc.co.uk/activities/exploring/tours/tabid/3422/id/5205/k/enjoy%20your%20morning%20cofee%20and%20evening%20cocktails%20on%20/p/1/nickis-beach-rides.aspx
which contains "enjoy%20your%20morning%20cofee%20and%20evening%20cocktails%20on%20" space as the last character that cause to stop this rule to work,
How can I add the above URL to work accordingly?
I have a rule in url rewrite module like below
<rule name="articleSectionUrl">
<match url="(.+)/([0-9]+)/(.+)/([0-9]+)" />
<action type="Rewrite" url="article.aspx?articleid={R:4}" appendQueryString="false" />
</rule>
It works properly as it detects below type of article url's:
http://www.emusician.com/news/0766/spl-launches-usb-and-madi-interfaces/151461
That's fine, but it also detects below type of url, which is the image path unfortunately:
http://www.emusician.com/Portals/9/SlideShowThumbnails/15/ad300x250_02.gif
Can anyone tell me how can i avoid this.
Thanks all, #Aquillo as per your regex it will just limit the file whose extension I provide in the regex, that means I always have to provide the extensions in the regex for the url I want to ignore, so here's the complete solution to my problem.
UrlRewrite module has a <conditions> element under <rule> with this we limit any type of file which comes in the url.
Here's the complete solution:
<rule name="articleSectionUrl">
<match url="(.+)/([0-9]+)/(.+)/([0-9]+)" />
<action type="Rewrite" url="article.aspx?articleid={R:4}" appendQueryString="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
</rule>
Thanks guys for helping me.
I'm trying to use IIS7 Url Rewrite module rewrite
services.mydomain.com/some-file-here to mydomain.webhost.com/folder/some-file-here
The rule is as follows:
Pattern = ^services.mydomain.com/(.*)$
Action = Rewrite
Rewrite URL = http://mydomain.webhost.com/folder/{R:1}
The problem is IIS keeps giving me 404 not found errors. I've been stuck at this for days now. Any ideas?
You have your pattern wrong. It should not include domain name or query string there -- only path without leading slash. See the working rule below:
<rule name="MyRewriteRule" stopProcessing="true">
<match url="^(some-file-here)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^services\.mydomain\.com$" />
</conditions>
<action type="Redirect" url="http://mydomain.webhost.com/folder/{R:1}" />
</rule>
The above rule will only trigger if host name is services.mydomain.com. If you do not require such additional condition (which is optional) then just remove these 3 lines: <conditions>...</conditions>
Also, the above rule will only do one specific redirect from services.mydomain.com/some-file-here to mydomain.webhost.com/folder/some-file-here. If you need to redirect ANY file like that, then use this one instead:
<rule name="MyRewriteRule" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^services\.mydomain\.com$" />
</conditions>
<action type="Redirect" url="http://mydomain.webhost.com/folder/{R:1}" />
</rule>