Add Exception To URL Rewrite And IIS Server - exception

I have my first IIS Server set up and running. And I have successfully configured the URL Rewrite add on. It works perfectly for all incoming requests. How ever I want to exclude one additional website that runs on the same IIS server. Can someone teach me how to do this?
web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="^(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<serverVariables>
<set name="HTTP_REFERER" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
<action type="Rewrite" url="http://working.backendserver:4588/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Base, Form, Img" pattern="^http(s)?://working.backendserver:4588/(.*)" />
<action type="Rewrite" value="http{R:1}://working.inbound.url.com/{R:2}" />
</rule>
<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
<preCondition name="NeedsRestoringAcceptEncoding">
<add input="{RESPONSE_CONTENT_TYPE}" pattern=".+" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
enter code here

Related

How to force site to use https only

I'm tryin to force my website to only accept https, by adding the following to my webconfig:
<clear />
<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>
This works, if you load the site using http it now re-directs the site to https, but every time I try to go to a different page or submit a form I get a:
405 - HTTP verb used to access this page is not allowed.
This currentle my webconfi:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="PW_BADPOST" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" />
<add input="{HTTP_REFERER}" pattern=".*\/wp-admin.*" />
</conditions>
<action type="CustomResponse" statusCode="404"/>
</rule>
<rule name="PW_BadURL" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="\.php" />
<add input="{REQUEST_URI}" pattern="die\(" />
<add input="{REQUEST_URI}" pattern="connector\.asp" />
</conditions>
<action type="CustomResponse" statusCode="404"/>
</rule>
<!-- directories to ignore -->
<rule name="PW_IgnoreDir" stopProcessing="true">
<match url="^(css|img|images|js|tools)\/(.*)$" ignoreCase="true" />
<action type="None" />
</rule>
<!-- Pages -->
<rule name="PW_Pages" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?{R:1}" />
</rule>
</rules>
</rewrite>
<directoryBrowse enabled="false" />
</system.webServer>
</configuration>

Angular universal web config file with ssl and www redirecting

I have a little problem with the web.config file of my angular universal project. My web.config file is like this;
<configuration>
<system.webServer>
<!-- indicates that the server.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="main.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="sendToNode">
<match url="/*" />
<action type="Rewrite" url="main.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
We are trying to add a www redirecting when there is no www written into link and a https redirecting when there is no https written in the url. But we couldnt manage to do this.
Should I need to do something from the Angular for this?
How can we add those two redirectings into our angular universal web config?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime enableVersionHeader="false" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000"/>
<add name="X-Content-Type-Options" value="nosniff" />
<add name="X-Frame-Options" value="DENY" />
<add name="X-XSS-Protection" value="1; mode=block" />
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the main.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="main.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
</rule>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^main.js\/debug[\/]?" />
</rule>
<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<match url="^(?!.*login).*$"></match>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
</conditions>
<action type="Rewrite" url="main.js"/>
</rule>
</rules>
<outboundRules>
<rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
<match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" />
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
</conditions>
<action type="Rewrite" value="max-age=31536000" />
</rule>
</outboundRules>
</rewrite>
<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>
<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />
<!-- Restart the server if any of these files change -->
<iisnode watchedFiles="web.config;*.js;browser/*.*" />
</system.webServer>
</configuration>

How to rewrite query in IIS 7

I want to rewrite this URL
https://www.website.com/parameter-1?query=100345046
To this
https://www.website.com/parameter?query=100345046
Basically I want the -1 removed from the URL.
I made an example which works, using RegExr, but I don't know how to implement this using the IIS.
So far I made this rule but I can't get the query part after the -1 to stick the to rewrote URL.
<rule name="Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="^/parameter-1$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/parameter" appendQueryString="true" />
</rule>
Alright I figured it out.
<rule name="Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="/parameter-1\?query=(.*)$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/parameter?" appendQueryString="true" redirectType="Permanent" />
</rule>

hide/remove url extension in windows servers

I read that .htaccess doesn't work on windows server like godaddy. So to hide or remove extensions like .php and .html on URL, you can accomplish this by creating a web.config file with the following code:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteHTML">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions> <action type="Rewrite" url="{R:1}.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I tried to make web.config file and save it where index.php is with that code but nothing happened.. I tested it with the like this
<ul>
<li>
Attack on Titan Episode 3
</li>
</ul> with a href of "attackontitan-3"
I want url to be http://mysite/watching/attack%20on%20titan/attackontitan-3 not http://mysite/watching/attack%20on%20titan/attackontitan-3.php
Use rewrite to add the extension, like this:
<rule name="rewritephp">
<!--Removes the .aspx extension for all pages.-->
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
Or This tutorial does a great job at explaining what you need to do with IIS.
http://atlantawebsites.blogspot.com/2010/06/vanity-urls-with-godaddy-hosting-using.html
You need to add a Rewrite and Redirect rules. The following will redirect and rewrite page.php to just page. If you want to do the same for html, just add those rules.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!-- Remove the existing rules just incase we already defined them -->
<remove name="RedirectPhpExtensions" />
<remove name="RewritePhpExtensions" />
<!-- Add a rule to redirect x.php pages to just x -->
<rule name="RedirectPhpExtensions" enabled="true" stopProcessing="true">
<match url="(.*)\.php$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<!-- Add a rule to rewrite the x pages to x.php behind the scene -->
<rule name="RewritePhpExtensions" enabled="true" stopProcessing="true">
<match url="(.*)" negate="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Place this web.config in the root directory of your domain.
Then you need to restart the Application Pool on godaddy's site:
Web Hosting > Manage > IIS Management > Recycle App Pool button

IIS 7 outbound rule not rewriting HTML href

I am trying to rewrite a html response with an outboundrule, but it is not working: This are my inbound and outbound rules:
<rules>
<rule name="IE56 Do not gzip js and css" stopProcessing="false">
<match url="\.(css|js|emz|jpg|htm|html)" />
<action type="None" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
<rule name="Route the requests for eserver" patternSyntax="ECMAScript">
<match url="^eServer/(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://mckyesvr/eServer/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame,Img, Input, Link, Script" pattern="^http(s)?://mckyesvr/eServer/(.*)" ignoreCase="true" />
<conditions>
<add input="{URL}" pattern="/PageLoader" negate="true" />
</conditions>
<action type="Rewrite" value="/eServer/{R:2}" />
</rule>
<rule name="ReverseProxyOutboundRule8" preCondition="ResponseIsHtml1">
<match pattern="http://mckyesvr/eServer/PageLoader.asp?Page=Process_Safety.dsp"/>
<action type="Rewrite" value="/eServer/PageLoader.asp?Page=Process_Safety.dsp" />
</rule>
They work perfectly with almost every HTML response except with the ones that have this HTML reponses form:
"<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
.......etc and this is the part that I want to rewrite:
<_a href="http://mckyesvr/eServer/PageLoader.asp?Page=Process_Safety.dsp"
target="_parent">Go Back to Process Safety------
I have tried changing the compressing, change the outbound rules, move a thousand parameters but nothing has worked out until now, I don't know why this is happening just with an HTML response as the one indicated above, it looks like it is coded because Outboundrules don't catch it.