Can someone please let me know why the following will not rewrite correctly?
<rule name="Redirect account listing with levelId" stopProcessing="true">
<match url="^account/([^/]+)/([^/]+)/([^/]+)[?levelId=]$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="account/{R:1}/{R:2}/{R:3}" appendQueryString="false" />
I'm trying to redirect so that the "?levelId= is removed.
I figured it out...
<rule name="Redirect account listing with levelId b" stopProcessing="true">
<match url="^account/([^/]+)/([^/]+)/([^/]+)" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^levelID=([^=&]+)$" />
</conditions>
<action type="Redirect" url="account/{R:1}/{R:2}/{R:3}" appendQueryString="false" />
Related
I need to redirect the user every time he enters subdomain.mywebsite.com to subdomain.mywebsite.com/app
I tried to do the following
<rewrite>
<rules>
<rule name="MyRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^subdomain.mywebsite.com$" />
</conditions>
<action type="Redirect" url="https://subdomain.mywebsite.com/app" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
But it gives me 'redirect multiple times' error
Please advice
UPD: I also need it to work for https
https://subdomain.mywebsite.com
So every time the user opens subdomain.mywebsite.com with HTTP or HTTPS it should forward to https://subdomain.mywebsite.com/app
That's because your rule also works for https://subdomain.mywebsite.com/. So it keep redirecting to itself.
Please add a condition pattern {HTTPS}=off to only redirect http request.
<rule name="MyRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^subdomain.mywebsite.com$" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://subdomain.mywebsite.com/app" redirectType="Permanent" />
</rule>
5/7Edit:
Please try this rule
<rule name="MyRule" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^subdomain.mywebsite.com$" />
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="https://subdomain.mywebsite.com/app" redirectType="Permanent" />
</rule>
<rule name="My Rule2" enabled="true" stopProcessing="true">
<match url="^app(/)?$" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^subdomain.mywebsite.com$" />
<add input="{HTTPS}" pattern="^on$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="https://subdomain.mywebsite.com/app" />
</rule>
<rule name="MyRule3" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^off$" />
<add input="{HTTP_HOST}" pattern="^subdomain.mywebsite.com$" />
</conditions>
<action type="Redirect" url="https://subdomain.mywebsite.com{REQUEST_URI}" />
</rule>
I am having a hard time getting the below redirect rule to work...
<rules>
<rule name="Relative Path Rewrite" stopProcessing="false">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/$" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
<rule name="Ssl Redirect" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
The issue is as follows...
If i enter http://mywebsite.com it redirects to https://mywebsite.com no problem.
however, if i enter http://mywebsite.com/faq it is redirecting to https://mywebsite.com instead of https://mywebsite.com/faq and i cannot figure out why? It appears to be ignoring the '{R:1}' back reference that would come from my match which should be 'faq'
I've been battling with this for a while, any ideas on what is going on here would be great.
Some additional information is that i am hosting an angular 4.0 site that this rule is applied to...
Reversing the rules worked.
<rewrite>
<rules>
<rule name="Ssl Redirect" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Relative Path Rewrite" stopProcessing="false">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/$" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
I've been trying to create user-friendly urls for two of my cfm pages using url rewrite module on IIS 8. That said, there seems to be some sort of conflict due to similarity between rules or something.
Here is what I want to achieve. The following pages:
www.mywebsite.com/news.cfm?category=microsoft
www.mywebsite.com/news.cfm?category=apple
etc
www.mywebsite.com/blog.cfm?title=sometitle
www.mywebsite.com/blog.cfm?title=sometitle
etc
Should look like this:
www.mywebsite.com/news/microsoft
or this
www.mywebsite.com/microsoft
www.mywebsite.com/blog/sometitle
or this
www.mywebsite.com/sometitle
You get the picture.
Here is my code:
<rule name="RedirectUserFriendlyURL4" stopProcessing="true">
<match url="^news\.cfm$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^category=([^=&]+)$" />
</conditions>
<action type="Redirect" url="news/{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL4" stopProcessing="true">
<match url="^news/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="news.cfm?category={R:1}" />
</rule>
<rule name="RedirectUserFriendlyURL5" stopProcessing="true">
<match url="^blog\.cfm$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^title=([^=&]+)$" />
</conditions>
<action type="Redirect" url="blog/{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL5" stopProcessing="true">
<match url="^blog/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="blog.cfm?title={R:1}" />
</rule>
The rules above do not work together and both pages redirect to the one that's set in the first rule. Can this be done with a single rule or do I need to use two? How can I sort this out? I would really appreciate your help on this one. I am using ColdFusion 10 on Windows and IIS 8.
I can redirect and make a single Friendly URL:
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^Product/Tour\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="Product/Tour" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL2" stopProcessing="true">
<match url="^Product/Tour$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="Product/Tour.aspx" />
</rule>
But, for example, if I have:
http://www.domain.com/Product/Features.aspx
http://www.domain.com/Product/Download.aspx
http://www.domain.com/Product/FAQ.aspx
etc.
Can I write one rule to make friendly URL for all of these links in order to receive?
http://www.domain.com/Product/Features
http://www.domain.com/Product/Download
http://www.domain.com/Product/FAQ
It's easy when there is a couple of links, but with a lot of rules it's hard to maintain.
You can use the regex pattern and the back reference to do this:
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^Product/([A-z0-9]+)\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="Product/{R:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL2" stopProcessing="true">
<match url="^Product/([A-z0-9]+)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="Product/{R:1}.aspx" />
</rule>
If you have a lot of urls to rewrite, you should read the documentation about the Rewrite Maps as well.
Ok, this is driving me nuts... I'm trying to rewrite my urls like this:
Now:
http://www.somedomain.com/Somepage.aspx
http://www.somedomain.com/AnotherPage.aspx
Desired:
http://www.somedomain.com/somepage/
http://www.somedomain.com/anotherpage/
Can anyone help me out with this? The terms in the User Interface are damn confusing.
Thanks.
I found the answer:
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="^([^\.]+)\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" negate="true" pattern="^POST$" />
</conditions>
<action type="Redirect" url="{ToLower:{R:1}}/" appendQueryString="false" redirectType="Permanent" />
</rule>
<rule name="Rewrite" stopProcessing="true">
<match url="^([^/]+)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
</rules>
</rewrite>