How to rewrite only category and heading of the page in URL web config - web-config

I was trying to change the URL by using this rule:
<rule name="Rewrite to news page">
<match url="^news/([_0-9a-z-]+)/([\s\S]+)" />
<action type="Rewrite" url="page.php?id={R:1}&title={R:2}" />
</rule>
but I don't want to use an id in the URL.

Related

URL rewrite loses Virtual Directory prefix using JavaScript root-based urls

We have some third-party service on http://localhost:1234/, and we want to be able to access it externally via https://my-site.com/MyService/
For that we have IIS with Virtual Directory (Application) MyService and URL rewrite rule
<rule name="my-service" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<action type="Rewrite" url="http://localhost:1234/{R:0}" />
</rule>
This service renders html with some root urls like Page 1
But following such links will lead us to https://my-site.com/MyService/page1.html
In order to fix it we have another URL rewrite outbound rule
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img, Link, Script" pattern="^/(.*)" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="https://my-site.com/MyService/{R:1}" />
</rule>
And it works fine and renders absolute urls Page 1
However, if we have JavaScript
// redirect
location.href = "/page2.html";
// AJAX
var xhr = new XMLHttpRequest();
xhr.open("GET", "/page2.html");
xhr.send();
// fetch
fetch("/page2.html");
those root-based urls will be resolved as https://my-site.com/MyService/page2.html
As this service is third-party, I can't just go to modify all those JavaScript code to include /MyService prefix. And those urls such as /page2.html are constructed dynamically so it's impossible to just use URL rewrite module to fixup corresponding JavaScript.
I was trying to add URL rewrite to the root website to capture such urls via http referer
<rule name="MyService" stopProcessing="true">
<match url="^(?!MyService).+$" />
<conditions>
<add input="{HTTP_REFERER}" pattern="https://my-site.com/MyService*" />
</conditions>
<action type="Redirect" url="https://my-site.com/MyService/{R:0}" redirectType="Found" />
</rule>
but it still doesn't work properly and behaves very fragile.
Is there a way to solve such supposedly very common task easily?

Web.config mass 301 redirect old news page to a slightly different Urls

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>

IIS: Redirect multiple URL's to same website

I'm looking for the best way to redirect multiple URL's to one new URL.
I have the following URLS:
https://domain.app.company.com/application
https://application.app.company.com
And I want those to redirect to: https://application.domain.app.company.com
What would be the best way to go about this (in IIS)?
I have tried using URL Rewriting, but I can only make that work for the first URL (https://domain.app.company.com/application):
<rule name="Application 1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*application" />
<action type="Redirect" url="https://application.domain.app.company.com" appendQueryString="false" />
</rule>
For the second URL (https://application.app.company.com), I can make it work when setting up a new (empty) website in IIS (that listens to said URL) and add a httpRedirect in it.
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="https://application.domain.app.company.com" exactDestination="true" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
Is this the recommended way to go about this? Or would there be another way?
Thank you
Schoof
If you want to bind two url for the same IIS web site, I suggest you could try to below url rewrite. We could create two url rewrite rule to achieve your requirement.
<rule name="Application 1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*application" />
<action type="Redirect" url="https://application.domain.app.company.com" appendQueryString="false" />
</rule>
<rule name="test" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="application.app.company.com" />
</conditions>
<action type="Redirect" url="https://application.domain.app.company.com" />
</rule>

How do I redirect www.mypage.com/this/that to www.mypage.com in IIS

<rule name="url rewrite"
stopProcessing="true">
<match url="This/That/Something(.*)$" />
<action type="Redirect"
url="" />
</rule>
What do i put in the in the action url to just have it redirect to the current domain.
trying to turn www.mypage.com/this/that/whatever.aspx to this www.mypage.com
If you want to redirect to homepage, you can just use /. It will looks like that
<rule name="url rewrite" stopProcessing="true">
<match url="This/That/Something(.*)$" />
<action type="Redirect" url="/" />
</rule>
For ex. if you want to redirect to www.mypage.com/abc, you can use like that:
<rule name="url rewrite" stopProcessing="true">
<match url="This/That/Something(.*)$" />
<action type="Redirect" url="/abc" />
</rule>
In case if you want to redirect to another domain www.otherdomain.com, you should use it like that:
<rule name="url rewrite" stopProcessing="true">
<match url="This/That/Something(.*)$" />
<action type="Redirect" url="http://www.otherdomain.com" />
</rule>

web.config rewrite complete URL

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>