Right now we have a bunch of extra directories with an index.htm in them that handle redirects to pages within our application. Instead of littering our folder structure with these, is there a way to us URL rewrite to redirect a user without completely breaking 404 errors?
For example,
domain.com/login
Would redirect to
domain.com/user/accountLogin.htm
Or
domain.com/happypartnercompany
Could go to
domain.com/partners/about.xyz?partner=123
For anyone else looking for a simple example, this is what I ended up doing:
<rule name="members" stopProcessing="true">
<match url="^members*$" ignoreCase="true" />
<action type="Rewrite" url="index.xyz?m=home/members/list" />
</rule>
And to actually redirect the user:
<rule name="member_signup_1" stopProcessing="true">
<match url="^sefcu*$" ignoreCase="true" />
<action type="Redirect" url="index.xyz?m=signup/enroll&partnerid=8532" />
</rule>
Ampersands must be escaped with & in the URL.
Related
I've got the following redirect rule below to force all http traffic to https. However, we need to serve some pages that have a problem displaying in https and we need to force them to be http until we can get them updated to work under https.
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
One thing all these pages have in commons in that "/SSLA/" is part of the url. I'm not the rewrite guru I would like to be, but there are a couple of potential ways I can think of to fix this:
a) Somehow update this rule to exclude urls with "/SSLA/".
B) Add a rule before this rule that catches anything with "/SSLA/" and redirects to http if it's going to https and (either in the same rule or a separate rule?) also does nothing for http requests but stops processing so it doesn't hit this global http to https redirect rule.
Problem is, I'm not great with either regex or rewrite rules so I'm not quite sure how to accomplish either of those solutions (actually not even sure even either are the "proper" way to handle this).
So... please help! :)
EDIT: I should note that I have updated the c# code to redirect to http for these pages, but of course that causes a loop with the above rule. But I just point this out to say that all I need is for the redirect rules not to force http requests for pages with "/SSLA" to https since the code will redirect any such https requests to http. But if it's a trivial matter to also have the redirect rule force https requests with "/SSLA/" in them to http then I could remove the c# code that does the same.
try use
<match url="((?!SSLA).)*" />
insteed
<match url=".*" />
You should use two rewrite rules:
For redirecting HTTPS -> HTTP for SSLA/* pages
For redirecting HTTP -> HTTPS for non SSLA/* pages.
Check my example below how I am filtering SSLA and non SSLA pages
<rule name="Redirect to http SSLA" stopProcessing="true">
<match url="^SSLA" />
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Redirect to https" stopProcessing="true">
<match url="^SSLA" nagate="true" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
I've got some IIS rewrite rules in place, and everything is working fine. But i feel like i can consolidate them.
Here are my rules:
<rule name="Blog - Advice - root" patternSyntax="ExactMatch" stopProcessing="true">
<match url="advice" />
<action type="Rewrite" url="https://mysite.wpengine.com/advice" />
</rule>
<rule name="Blog - Advice - root (with slash)" patternSyntax="ExactMatch" stopProcessing="true">
<match url="advice/" />
<action type="Rewrite" url="https://mysite.wpengine.com/advice" />
</rule>
<rule name="Blog - Advice" stopProcessing="true">
<match url="^advice/?(.*)" />
<action type="Rewrite" url="https://mysite.wpengine.com/advice/{R:1}" />
</rule>
I want to match the following examples:
/advice
/advice/ (should rewrite without the slash)
/advice/sdfsdf
/advice/sdfsdf/ (should rewrite without the slash)
/advice/sdfdsf/sdfds
Can it be done with 1 (or 2) routes?
If i leave the second one out for example, Wordpress (the site i'm rewriting to), will do a 301 redirect to a URL without the slash, and i lose the rewrite since the URL is changed again. (so i end up at mysite.wpengine.com/advice, which is wrong).
So i need to make sure any rewrites don't involve a redirect on the target site end.
Many thanks :)
I want my domain homepage to be redirected to one of my mvc directories
this is the rule i am using
<rule name="Home" stopProcessing="true">
<match url="^/*$" />
<action type="Rewrite" url="/test/" logRewrittenUrl="true" />
</rule>
Same rule is working if i put redirect. But rewrite is not working.
Other URLS should be served normally. Only home page should be rewritten
Can we achieve this without ARR?
//www.example.com should be rewritten to //www.example.com/test/
www.example.com/buy should be served as it is.
Your regex is incorrect. Correct rule is:
<rule name="Home" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="/test/" logRewrittenUrl="true" />
</rule>
And this rule will work without ARR because you rewriting to a subfolder in the same website. If you want to rewrite to the different website in IIS, then you need ARR.
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" />
I have a website configured on IIS and multiple domains configured on my hosts file to point to my localhost.
My problem is that I need to redirect all the requests from:
http://domain.com/folder/ to http://domain.com/
So a request for
http://domain.com/folder/test/image.jpeg should be transformed into:
http://domain.com/test/image.jpeg
I can't change the files because I'm trying to emulate a cdn behavior.
Can anyone help?
Thanks
Joao
Using the rewrite module, you can go with:
<rule name="skip folder" stopProcessing="true">
<match url="^folder/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
The default redirect is a permanent (301).
If you want to keep the url http://domain.com/folder/test/image.jpeg but display the content http://domain.com/test/image.jpeg, then a rewrite has to be used:
<rule name="skip folder" stopProcessing="true">
<match url="^folder/(.*)$" />
<action type="Rewrite" url="{R:1}" />
</rule>