How can I convert IIS url rewrite rules to Tuckey rewrite rules? - mod-rewrite

I am having great difficulty in trying to modify these rewrite rules to a version of URL rewrite that can work with Tuckey.
They currently work with IIS / ColdFusion but I need these to work with a version of ColdFusion that is run within Commandbox which uses Tuckey rewrite.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
<rule name="Dont Follow" enabled="true" stopProcessing="true">
<match url="jrunscripts[.]*|javascripts[.]*|images[.]*|css[.]*|assets[.]*|CFIDE[.]*|cfide[.]*|CFFormGateway[.]*|stylesheets[.]*|Favicon.ico|lucee[.]*" />
<action type="None" />
</rule>
<rule name="ColdFusion on Wheels URL Rewriting" enabled="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{SCRIPT_NAME}" negate="true" pattern="^/(flex2gateway|jrunscripts|cf_scripts|cfide|CFFileServlet|cfformgateway|lucee|files|images|javascripts|miscellaneous|stylesheets|wheels/public/assets|robots.txt|favicon.ico|sitemap.xml|rewrite.cfm)($|/.*$)" />
</conditions>
<action type="Rewrite" url="/rewrite.cfm/{R:1}" />
</rule>
</rules>
</rewrite>
<defaultDocument enabled="true">
<files>
<clear />
<add value="index.cfm" />
</files>
</defaultDocument>
<httpErrors errorMode="DetailedLocalOnly">
<remove statusCode="502" subStatusCode="-1" />
<remove statusCode="501" subStatusCode="-1" />
<remove statusCode="412" subStatusCode="-1" />
<remove statusCode="406" subStatusCode="-1" />
<remove statusCode="405" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="401" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
</httpErrors>
</system.webServer>
<system.web>
<httpRuntime executionTimeout="1200" />
</system.web>
</configuration>

Related

Web.config Rewrite particular subfolders to querystrings

I have searched and tried many Rewrite rules but no one matched my requierement. In a particular folder (not entire the website) say http://www.example.com/company/ I want to rewrite all subfolders to execute a page with querystring. For example:
http://www.example.com/company/test
should show the content of
http://www.example.com/company/index.aspx?title=test
this was the closest answer to my question but is about the root folder of website not a particular folder so I could not figur out the logic of {R:0} {R:1} etc.
<rule name="Redirector" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{PATH_INFO}" pattern="/*" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/default.aspx?q={PATH_INFO}" appendQueryString="true" />
</rule>
Finally this worked for me:
<rule name="RedirectFolder" stopProcessing="true">
<match url="(^company/(.*))|(^company$)" />
<conditions>
<add input="{PATH_INFO}" pattern="/*" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="./company/index.aspx?q={R:2}" appendQueryString="true" />
</rule>

c#, IIS 10, Web Forms, Forms Authentication, Bootstrap 4, Web API, Trying to Add Signalr - getting 404 on signalr/hubs?

I've used each of the title technologies individually before. It's combining them that's become the issue.
Web App works perfectly on Dev machine with IIS Express (Visual Studio 2019).
When I publish, no SignalR. if I try to navigate to webaddress.com/signalr/hubs I get a 404 error.
the #1 fix: <modules runAllManagedModulesForAllRequests="true">
this "fixes" Signalr. but then there is no bootstrap on the pages and the <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> to fix the URL without Default.aspx, gets broken as well.
So I'm guessing there is a "module" that i have to use to get Signalr to work again and the "run allmanagedmodules" is too generic?
Here's my Web Config. Any Ideas?
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="XXXXXXXXX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<add name="XXXXXXXXXX" connectionString="Data Source=XXXXXXX\SQLEXPRESS;Initial Catalog=XXXXXXX;Integrated Security=false;user=XXXXXXX;password=XXXXXXX" />
</connectionStrings>
<system.web>
<customErrors mode="Off" />
<compilation targetFramework="4.6" debug="true" />
<httpRuntime targetFramework="4.6" />
<authentication mode="Forms">
<forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" defaultUrl="default.aspx" timeout="30" />
</authentication>
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
</system.web>
<location path="Default.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="signalr">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="Patient.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="aboutus.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="contact.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="iforgot.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="test.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="api/XXXX">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<applicationSettings>
<XXXXXXX.Properties.Settings>
<setting name="UserID" serializeAs="String">
<value>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</value>
</setting>
<setting name="FromEmail" serializeAs="String">
<value>XXXXXXX#xxxxxxxxxxxxxxxxxxxxxxx.com</value>
</setting>
<setting name="EmailUsername" serializeAs="String">
<value>xxxxxxxxxxxxxxxxxx\xxxxxxxxxxxxxxxx</value>
</setting>
<setting name="EmailPassword" serializeAs="String">
<value>XXXXXXXXXX</value>
</setting>
<setting name="EmailServer" serializeAs="String">
<value>mail.XXXXXXXXXXXXXXXXXXX.com</value>
</setting>
<setting name="Token" serializeAs="String">
<value>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</value>
</setting>
</XXXXXXX.Properties.Settings>
</applicationSettings>
<system.webServer>
<modules >
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
<!-- any other modules you want to run in MVC e.g. FormsAuthentication, Roles etc. -->
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
</handlers>
<rewrite>
<rules>
<rule name="HTTPS force" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

IIS gZip Compression Not Working event after Setting Everything

I deployed a simple html page with ajax (loading a json file) in my iis 8.0 (windows 8) and iis7+ (windows 7).
1. I enabled static and dynamic compression in IIS
2. I have written all the tags in we.config and the same has been attached.
Still I am not getting content-encoded: gZip in response header.
webconfig is like below
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/json" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<staticContent>
<!-- Set expire headers to 30 days for static content-->
<clientCache cacheControlMaxAge="30.00:00:00" cacheControlMode="UseMaxAge" />
<!-- use utf-8 encoding for anything served text/plain or text/html -->
<!-- in the case of .html files; if you AJAX load html files (i.e. in angular) then remove these two lines. -->
<remove fileExtension=".html" />
<mimeMap fileExtension=".html" mimeType="text/html; charset=UTF-8" />
<remove fileExtension=".css" />
<mimeMap fileExtension=".css" mimeType="text/css" />
<remove fileExtension=".js" />
<mimeMap fileExtension=".js" mimeType="text/javascript" />
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
<remove fileExtension=".rss" />
<mimeMap fileExtension=".rss" mimeType="application/rss+xml; charset=UTF-8" />
<remove fileExtension=".xml" />
<mimeMap fileExtension=".xml" mimeType="application/xml; charset=UTF-8" />
<!-- HTML5 Audio/Video mime types-->
<remove fileExtension=".mp3" />
<mimeMap fileExtension=".mp3" mimeType="audio/mpeg" />
<remove fileExtension=".mp4" />
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<remove fileExtension=".ogg" />
<mimeMap fileExtension=".ogg" mimeType="audio/ogg" />
<remove fileExtension=".ogv" />
<mimeMap fileExtension=".ogv" mimeType="video/ogg" />
<remove fileExtension=".webm" />
<mimeMap fileExtension=".webm" mimeType="video/webm" />
<!-- Proper svg serving. Required for svg webfonts on iPad -->
<remove fileExtension=".svg" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<remove fileExtension=".svgz" />
<mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
<!-- HTML4 Web font mime types -->
<!-- Remove default IIS mime type for .eot which is application/octet-stream -->
<remove fileExtension=".eot" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<remove fileExtension=".ttf" />
<mimeMap fileExtension=".ttf" mimeType="application/x-font-ttf" />
<remove fileExtension=".ttc" />
<mimeMap fileExtension=".ttc" mimeType="application/x-font-ttf" />
<remove fileExtension=".otf" />
<mimeMap fileExtension=".otf" mimeType="font/opentype" />
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<remove fileExtension=".crx" />
<mimeMap fileExtension=".crx" mimeType="application/x-chrome-extension" />
<remove fileExtension=".xpi" />
<mimeMap fileExtension=".xpi" mimeType="application/x-xpinstall" />
<remove fileExtension=".safariextz" />
<mimeMap fileExtension=".safariextz" mimeType="application/octet-stream" />
<!-- Flash Video mime types-->
<remove fileExtension=".flv" />
<mimeMap fileExtension=".flv" mimeType="video/x-flv" />
<remove fileExtension=".f4v" />
<mimeMap fileExtension=".f4v" mimeType="video/mp4" />
<!-- Assorted types -->
<remove fileExtension=".ico" />
<mimeMap fileExtension=".ico" mimeType="image/x-icon" />
<remove fileExtension=".webp" />
<mimeMap fileExtension=".webp" mimeType="image/webp" />
<remove fileExtension=".htc" />
<mimeMap fileExtension=".htc" mimeType="text/x-component" />
<remove fileExtension=".vcf" />
<mimeMap fileExtension=".vcf" mimeType="text/x-vcard" />
<remove fileExtension=".torrent" />
<mimeMap fileExtension=".torrent" mimeType="application/x-bittorrent" />
<remove fileExtension=".cur" />
<mimeMap fileExtension=".cur" mimeType="image/x-icon" />
<remove fileExtension=".webapp" />
<mimeMap fileExtension=".webapp" mimeType="application/x-web-app-manifest+json; charset=UTF-8" />
</staticContent>
<defaultDocument>
<files>
<add value="test.html" />
</files>
</defaultDocument>
</system.webServer>
</configuration>

IIS7 301 Redirects - The correct way

We have built a Wordpress site and the clients server is running Windows. I personally have never worked with a Windows server.
I am trying to get the 301 redirects to work. So far I have had no luck. We have a web.config file set up with the following:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
<add value="default.aspx" />
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="WordPress Rule" 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="index.php" />
</rule>
</rules>
</rewrite>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".ogv" mimeType="video/ogv" />
<mimeMap fileExtension=".webm" mimeType="video/webm" />
</staticContent>
</system.webServer>
</configuration>
This is working and the site is running as expected. But when I try adding the list of 301's in between < rules > tags they don't seem to work. I don't receive any errors, it just doesn't redirect when going to the old url. I have been advised by the server admin that the Routing Module has been installed.
My rule:
<rule name="301 Redirect 1" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="/insight/$" />
</conditions>
<action type="Redirect" appendQueryString="false" url="/services/insight/" redirectType="Permanent" />
</rule>
Another:
<rule name="301 Redirect 2" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="/contact-us/$" />
</conditions>
<action type="Redirect" appendQueryString="false" url="/contact/" redirectType="Permanent" />
</rule>
Is anyone able to advise?
----- EDIT -----
I have also tried:
<rule name="301 Redirect 2" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="\/contact-us\/$" />
</conditions>
<action type="Redirect" appendQueryString="false" url="/contact/" redirectType="Permanent" />
</rule>
I have also changed the pattern to match if a slash ( / ) is at the end of the url:
<rule name="301 Redirect 2" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="\/contact-us((\/\w+)+|\/?)$" />
</conditions>
<action type="Redirect" appendQueryString="false" url="/contact/" redirectType="Permanent" />
</rule>

Cannot send email from ELMAH for my asp.net mvc application

I could not able to send mail from ELMAH for my asp.net mvc application.
I am getting following exception.
An exception of type 'System.Net.Mail.SmtpException' occurred in
System.dll but was not handled in user code
which says my credentials are incorrect but it is correct because I am able to send email
by code using MailMessage class
Following is my web.config file settings for ELMAH.
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5" />
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<elmah>
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah-sql"></errorLog>
<errorMail from="test#test.com"
to="test#test.com"
subject="Application Exception"
async="false"
smtpPort="587"
smtpServer="smtp.office365.com"
userName="test#test.com"
enableSsl="true"
password="Dacu46361!">
</errorMail>
<security allowRemoteAccess="1" />
</elmah>
<location path="elmah.axd" inheritInChildApplications="false">
<system.web>
<httpModules>
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
</httpModules>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</modules>
</system.webServer>
</location>
Thanks for help in advance.
Configure mail settings in "system.net" section in web.config:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="origin#domain.com">
<network host="smtp.office365.com" enableSsl="true" port="587" userName="XXX" password="XXX"/>
</smtp>
</mailSettings>
</system.net>
Include in "elmah" section:
<errorMail from="origin#domain.com" to="target#domain.com" subject="Error in my domain.com" async="true" useSsl="true" />

Resources