Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS url rewrite role except some urls

I got this rule in URL rewrite that rewrites every request to the site using HTTP to HTTPS

<rule name="Force HTTPS" stopProcessing="true">                     <match url="(.*)" />                     <conditions>                         <add input="{HTTPS}" pattern="off" ignoreCase="true" />                     </conditions>                     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />                 </rule> 

I need another rule or exception in this role to rewrite back or redirect specific urls to HTTP.

Is that possible?

like image 449
dotmido Avatar asked Nov 10 '12 08:11

dotmido


People also ask

How do I redirect a specific URL in IIS?

In IIS Manager, expand the local computer, right-click the Web site or directory you want to redirect, and click Properties. Click the Home Directory, Virtual Directory, or Directory tab. Under The content for this source should come from, click A redirection to a URL.

What is the difference between URL Rewrite and redirect?

Simply put, a redirect is a client-side request to have the web browser go to another URL. This means that the URL that you see in the browser will update to the new URL. A rewrite is a server-side rewrite of the URL before it's fully processed by IIS.

What is Request_uri in URL Rewrite?

Returns exact URL what you requested. For example, if you have default.aspx file in the root and you will access your website root.

Does the URL in the browser change when a rewrite happens?

With rewrite, the client does not see anything and redirection is internal only. No URL changes in the browser, just the server understands it differently.


1 Answers

You can add the exceptions for which you don't want to perform the redirect to HTTPS as extra conditions (not equal to that URL), like so:

<rule name="Force HTTPS" stopProcessing="true">     <match url="(.*)" />     <conditions logicalGrouping="MatchAll">         <add input="{HTTPS}" pattern="off" ignoreCase="true" />         <add input="{REQUEST_URI}" negate="true" pattern="^/noredirect/forthis/page\.aspx$" ignoreCase="true" />         <add input="{REQUEST_URI}" negate="true" pattern="^/noredirect/forthis/page-as-well\.aspx$" ignoreCase="true" />         <add input="{REQUEST_URI}" negate="true" pattern="^/noredirect/forthis/page-as-well-too\.aspx$" ignoreCase="true" />     </conditions>     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" /> </rule> 
like image 128
Marco Miltenburg Avatar answered Sep 23 '22 17:09

Marco Miltenburg