I need to create easy to remember URL's that redirect to long and hard to remember paths for a large number of applications.
i.e.
subdomain.domain.edu/shortname
redirects to
https://www.subdomain.domain.edu/mainApplication/subfolder/page
I'm using the URL Rewrite module in IIS 8.5, but I keep getting a 404 when I browse to the short alias. I know the rewrite module is working as I use it to handle rewriting HTTP to HTTPS and to add WWW to a URL.
My rewrite rule looks like:
<rewrite>
<rules>
<rule name="Easy to remember shortcut" stopProcessing="true">
<match url=".*subdomain.domain.edu/shortname" />
<conditions>
<add input="{URL}" pattern=".*/shortname" />
</conditions>
<action type="Redirect" url="https://www.subdomain.domain.edu/mainApplication/subfolder/page.aspx" />
</rule>
</rules>
</rewrite>
Of course this returns a 404. Any ideas?
Forgive me if there is already an answer to this in another post, however, I've read through and tried over 30 posts on the URL rewrite module and have not yet found the solution for actually creating an alias.
Url rewrite match condition won't be able to see your domain i.e. if the URL is https://www.subdomain.domain.edu/shortname the match part can only see shortname (anything after domainname/).
To validate the host we need to add in the conditions clause. So your rule will be something like below
<rule name="shortnameURL" enabled="true" stopProcessing="true">
<match url="shortname" />
<action type="Redirect" url="mainApplication/subfolder/page" />
<conditions>
<add input="{HTTP_HOST}" pattern=".*subdomain.domain.edu" />
</conditions>
</rule>
Also it should be ok if you add the entire URL here
<action type="Redirect" url="mainApplication/subfolder/page" /> as below
<action type="Redirect" url="https://www.subdomain.domain.edu/mainApplication/subfolder/page" />
Related
How can convert url www.mydomain.com/home to www.mydomain.com/api/v1/home
if the requested api link don't contain api/v1
I need someone help to write iis rewrite rule in web.config to fit this case
best regards
if the requested api link don't contain api/v1
You can use the parameter ^home$ to make the requested url match only home, this way api/v1 is not contained.
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="^home$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.domainname.com$" />
</conditions>
<action type="Redirect" url="http://www.domainname.com/api/v1/home" appendQueryString="false" />
</rule>
</rules>
</rewrite>
Body cannot contain mydomain, so i use domainname instead of it.
URL Rewrite rule for a specific domain
if url is https and have this domain only
https://myServer/SomeApplication/
Redirect it to
https://myServer.mycompany.com/SomeApplication/
Added below didn't work in iis 10, windows server 2019
<rule name="httpsRedirect2" enabled="true" stopProcessing="true">
<match url="^myServer/(.*)" ignoreCase="true"/>
<action type="Redirect" url="https://myServer.mycompany.com/SomeApplication/" appendQueryString="false" />
</rule>
Can someone explain what I've done wrong?
The Rule pattern only can get the URL string as an input, does not include the query string, thus it will not work properly.
Here is an official explanation of how certain parts of the URL string can be accessed from a rewrite rule.
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#accessing-url-parts-from-a-rewrite-rule
We can match the hostname in the Rule Condition section then apply the Rule Action.
<rule name="Myrule2" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="localhost" />
</conditions>
<action type="Redirect" url="https://vabqia969vm/" />
</rule>
</rules>
</rewrite>
Feel free to let me know if the problem still exists.
I am struggling getting an IIS rewrite rule working.
The old urls look like:
https://wwww.testserver.com/package.aspx?TrackingNumber=number
The new web app is expecting the urls in this format:
https://wwww.testserver.com/package/number
Currently I have the following rule setup, which is not working.
<rule name="Rewrite to new Package site" stopProcessing="true">
<match url="^package\.aspx\?TrackingNumber=([_0-9a-z-]+)" />
<action type="Redirect" url="https://www.testserver.com/package/{R:1}" logRewrittenUrl="true" />
</rule>
The interesting part is, if I remove package.aspx\? from the rule, urls like these https://wwww.testserver.com/oldwebsite/TrackingNumber=number are getting matched.
In my test calls I replaced package.aspx with package.html and these urls are not getting matched as well. It looks like IIS ignores urls with filenames in the url.
You could use below url rewrite rule to redirect https://wwww.testserver.com/package.aspx?TrackingNumber=number to https://wwww.testserver.com/package/number:
<rule name="test" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="package(.aspx)" />
<add input="{QUERY_STRING}" pattern="TrackingNumber=(.*)" />
</conditions>
<action type="Redirect" url="http://localhost:2568/package/{C:1}" appendQueryString="false" />
</rule>
Note: You could modify hostname as per your requirement.
Regards,
Jalpa
I am new to the IIS Rewrite rule and trying to create a rule to replace part of url
e.g.www.abc.com/assets/global/xyz.jpg
should redirect to www.abc.com**/en/globalassets/**assets/global/xyz.jpg
I fiddle around with the following rule but no success
<rule name="url replace">
<match url="^(.com/assets/global/)" />
<action type="Rewrite" url=".com/en/globalassets/assets/global/{R:2}" />
</rule>
According to your description, I have tested on my side , you could use urlrewite rule as below:
<rule name="rule1" enabled="true" stopProcessing="true">
<match url="assets/global/(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="en/globalassets" negate="true" />
</conditions>
<action type="Redirect" url="http://{domain}/en/globalassets/assets/global/{R:1}" />
</rule>
Firstly, we couldn't add value like **.com in match url, because this part could only catch path of the url.
You could see this is a url structure:
http(s)://httphost/path?querystring.
You could only get it in conditions tag but not pattern.
Then you should add condition to check the request URL match "en/globalassets" or not to avoid running redirect rule once and once again.
I have seen a handful of similar questions on handling removing the www from a URL, but I was needing to remove it only when a certain directory exists. The real issue is that I run the "test" in URL Rewrite within IIS and it works fine, but for some reason does not respond when I type in the URL. I have tried switching to when "not matches" and it redirects, so I am a bit baffled what I am doing wrong to get this to work.
An example URL would be http://www3.test.com/feed/testing.xml
If the directory "feed" exists in the URL then remove the www3. I thought this would be fairly simple.
<rule name="fix feeds" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(www3\.)(.*)(feed/.*)" />
</conditions>
<action type="Redirect" url="http://{C:2}{C:3}" appendQueryString="false" redirectType="Permanent" />
Another issue I am finding is that if you set it to permanently redirect 301, then once you get something to fire (and may not work as expected) the browser caches the 301 redirect and makes a mess of your testing environment.
You can't match feed in HTTP_HOST instead you need to use Match URL.
You have to match /feed/testing.xml in match URL which will yield here R:0
Match your patter if it has www3 and take C:2 which will give you URL without www3.
<rule name="fix feeds" enabled="true" stopProcessing="true">
<match url="^feed/.*" />
<conditions>
<add input="{HTTP_HOST}" pattern="(www3\.)(.*)" />
</conditions>
<action type="Redirect" url="http://{C:2}/{R:0}" appendQueryString="false" redirectType="Permanent" />
</rule>