<rule name="Directories The" stopProcessing="true">
<match url="^Directories/The" />
<action type="Redirect" url="/" />
</rule>`
I have two url like this www.mydomain/Directories/the and www.mydomain/Directories/the-hindu. But i only want to redirect first url only. If i put above code two urls are redirecting.
I tried with exact match and wild card also not working. I dont want www.mydomain/Directories/the-hindu to my home page
`
The problem is that your regexp ^Directories/The is matching for both URLs:
www.mydomain/Directories/the
www.mydomain/Directories/the-hindu
You need to add the end of string condition to your regexp. The correct rule should be:
<rule name="Directories The" stopProcessing="true">
<match url="^Directories/The$" />
<action type="Redirect" url="/" />
</rule>`
And this rule will match only www.mydomain/Directories/the
Related
I need to redirect a bunch of news articles to a different url format using web.config.
For example, this Url:
https://www.example.com/footer/press-resources/press-releases/press-release-detail/abcd-press-release-item
Should be redirected to this Url:
https://www.example.com/about/press-releases/press-release-detail/abcd-press-release-item
In this example, as you can see this portion of the Url is staying intact /press-release-detail/abcd-press-release-item but everything else before this should be redirected. The only dynamic part of the Url is the article's title which is at the end of the Url, in this case: abcd-press-release-item
I have about 300 items, obviously redirecting them one by one is going to take some time. Is there a way to rule them all out and mass redirect the old Urls to the new ones?
This is a Windows/IIS server with a .NET CMS and a web.config file.
I tried this rule and it didn't work for me:
<rule name="301 Redirect 1" stopProcessing="true">
<match url="^https://www.example.com/footer/press-resources/press-releases/press-release-detail\$" />
<action type="Redirect" url="https://www.example.com/about/press-releases/press-release-detail" redirectType="Permanent" />
</rule>
Try to use this URL Rewrite rule:
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="(footer)/(press-resources)(.*)" />
<action type="Redirect" url="https://www.example.com/about{R:3}" />
</rule>
</rules>
</rewrite>
Say I have my api under this url
http://www.example.net/api/trythis and I would like to redirect to http://www.example.net/api/v1/trythis, so in future I can have http://www.example.net/api/v2/trythis or http://www.example.net/api/v3/trythis
I am thinking of doing this in web.config:
<system.webServer>
<rewrite>
<rules>
<rule name="Root Hit Redirect" stopProcessing="true">
<match url="/api/*" />
<action type="Redirect" url="/api/v1/*" />
</rule>
</rules>
</rewrite>
</system.webServer>
However, if someone access url /api/v2/trythis or /ap1/v3/trythis, won't they be redirected to /api/v1/trythis? So it will defeat the purpose of versioning?
According to your rules, it will cause multiple redirect errors. Since the "api/v1" also matches the "api".
To solve this issue, you should set the condition in your url rewrite rule to avoid multiple matching.
Details, you could refer to below rule:
<rule name="Root Hit Redirect" stopProcessing="true">
<match url="api/(.*)" />
<action type="Redirect" url="http://yousitedomain.com/api/v1/{R:1}" />
<conditions>
<add input="{PATH_INFO}" pattern="api/v1/(.*)" negate="true"/>
</conditions>
</rule>
If you want to avoid v2,v3, I suggest you could add multiple condition as above setting.
Hi there,
Just a simple question. I Have a Domain with path, let's say exampleme.com, and this page has a specific page: exampleme.com/game.php. Is there a way to completely rewrite the link to another domain on that page? So that exampleme.com/game.phpbecomes game.com?
I've tried this, but since I'm fairly new to the web.config rewrite module, I'm a bit clueless.
` <rule name="Examplerule">
<match url="http://game.com" ignoreCase="false" />
<action type="Rewrite" url="/game.php" appendQueryString="false" />
</rule>`
Rewrite works only on your current domain. You need an redirect.
<rules>
<rule name="Game" stopProcessing="true">
<match url="/game.php" />
<action type="Redirect" url="http://game.com" />
</rule>
</rules>
I was looking into this Seemingly simple redirect in IIS using web.config file because I have a similar situation, but the approach mentioned there doesn't seem to be working for me.
I have a help section on a web site, which for now I want it to redirect to another place. The rest of the site should stay the same, which means that only the help section/content should make the user go to another site:
device.domain.com/help
device.domain.com/help/version
Should make the request go to
company.custhelp.com
But for example device.domain.com/api should still work. This is what I tried. If I test the pattern inside of IIS it says that it will work. What am I missing?
<system.webServer>
<rewrite>
<rules>
<rule name="Help Redirect" stopProcessing="true">
<match url="(.*)/help(.*)" ignoreCase="true" />
<action type="Redirect" url="http://company.custhelp.com/" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
...
</system.webServer>
The match url will try to match on the path after the domain, starting from after the slash. So it should be like so:
<match url="help(.*)" ignoreCase="true" />
The match url that you wrote would match on device.domain.com/temp/help, but not device.domain.com/help.
I have written this rule in webconfig to redirect all my resources in thsi folder to my azure blob but it is not showing any image there.
<rule name="RewriteIncomingCdnRequest" stopProcessing="true">
<match url="^/CDN/(.*)$" ignoreCase="false"/>
<action type="Redirect" redirectType="Permanent" url="https://stplatformstorage.blob.core.windows.net/static/{R:0}" />
</rule>
http://sttest.azurewebsites.net/CDN/image_cdn-trans.png
this should redirect to azure storage....
image url on storage
https://stplatformstorage.blob.core.windows.net/static/image_cdn-trans.png
you have a bad regular expression - as written, url="^/CDN/(.*)$" would only match /CDN/image_cdn-trans.png - because "^" means "from start of..." -- what you really need is url="^.*/CDN/(.*)$" and then use the matching group {R:1} - for:
<rule name="RewriteIncomingCdnRequest" stopProcessing="true">
<match url="^.*/CDN/(.*)$" ignoreCase="false"/>
<action type="Redirect" redirectType="Permanent" url="https://stplatformstorage.blob.core.windows.net/static/{R:1}" />
</rule>
The URL Rewrite module has a great test function to test your regular expressions.