Lets encypt challenge requests fail when virtual path is modified and not wwroot - web-config

I'm switching to Lets Encrypt for all my certs and the web jobs are failing on my Laravel and Zend apps because the challenge requests fail. For my static sites everything works fine, for the Laravel/Zend sites the virtual path has been modified from 'wwwroot' to 'wwwroot/public'.
I'm not sure what I need to add to my web.config file to pass the challenge requests through to '/well-known/acme-challenge'.
My web.config is as below, I've tried moving the contents of the '/.well-known/acme-challenge/web.config' into it, tried to pass through challenge requests to '/.well-known...', added other mappings, I can't get anything to work.
Up until now, to renew the certs every quarter I have been modifying the virtual path back to 'wwwroot' and then manually running the web job, obviously this isn't a good solution.
web.config for my app
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
web.config for ./well-known/acme-challenge
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<clear />
<add name="ACMEStaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="Either" requireAccess="Read" />
</handlers>
<staticContent>
<remove fileExtension="." />
<mimeMap fileExtension="." mimeType="text/plain" />
</staticContent>
</system.webServer>
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</configuration>
I'm using 0.9.3 of the Azure Let's Encrypt extension by SJKP
Thank you in advance.

Turns out I have answered this myself.
I needed to add a path mapping.
Virtual path: /.well-known
Physical path: site\wwwroot.well-known
Type: Directory

Related

MagicChunks not writing web.config attribute

I have this block in my web.config:
<rewrite>
<rules>
<rule name="Remove Trailing Slash" stopProcessing="false">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}" />
</rule>
<rule name="Angular UI Router - HTML5 Mode" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="/api/" negate="true" />
</conditions>
<action type="Rewrite" url="/app/" />
</rule>
</rules>
</rewrite>
In an Azure release pipeline I'm using the MagicChunks tool to transform the web.config to change the second action elements' url attribute to "/" but it is failing. The transform I have is:
{
"rewrite/rules/rule/action[#type='Rewrite' and #url='/app/']/#url": "/"
}
The error it throws up is:
System.ArgumentException:***There***is***empty***items***in***the***path.
How can I target an attribute to be transformed when it is not the attribute(s) being used as the target path?
Not sure how your web.config looks like, but there's something wrong with your transform syntax. Check document from that extension. You should use something like:
{
"rewrite/rules/rule[#name='Angular UI Router - HTML5 Mode']/action[#type='Rewrite']/#url": "/"
}
Since I tested your script in this way:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
</system.web>
<rewrite>
...
</rewrite>
</configuration>
So I actually used something like:
{
"configuration/rewrite/rules/rule[#name='Angular UI Router - HTML5 Mode']/action[#type='Rewrite']/#url": "/"
}
Be careful about the root node in your web.config. Then it should work well to replace the url attribute to "/". Let me know if I misunderstand anything :)

IIS got ERR_TOO_MANY_REDIRECTS on rewrite rule

I'm trying to create an IIS rule to redirect mobile users to the mobile site.
The main site (desktop version) is in the root route ('/'), and the mobile site is in the route '/mobile'
I created this IIS rule, but when I try it in desktop it's work well, but in mobile, I got an error ERR_TOO_MANY_REDIRECTS
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Mobile" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="true"/>
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-Device-User-Agent}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-OperaMini-Phone-UA}" pattern="midp|mobile|phone" />
</conditions>
<action type="Redirect" url="mysiteurl/mobile" appendQueryString="false" />
</rule>
</rewrite>
</system.webServer>
</configuration>
It is happening because your rule is also matching all mobile URLs. You need to exclude mobile URLs from your rule. This rule will work for you:
<rule name="Rewrite Mobile" enabled="true" stopProcessing="true">
<match url="mobile(.*)" negate="true"/>
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-Device-User-Agent}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-OperaMini-Phone-UA}" pattern="midp|mobile|phone" />
</conditions>
<action type="Redirect" url="/mobile" appendQueryString="false" />
</rule>

How to use Zend framework in window server

How can I use Zend Framework in window server ? I know that on window server the .htaccess file isn't supported so I have created a web.config file but this still not working.This is my web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="index-bootstrap">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<match url=".?" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
Read articles. They should help you with the problem:
https://davekz.com/install-the-zend-framework-on-iis7-5/
http://blog.richardknop.com/2011/09/making-zend-framework-run-under-iis/

How to use web.config with two domains

I have this cenario:
In my principal domain i have my blog under permalink wordpress
In an folder /xyz i have an other domain abc.com.br pointed.
How to construct rules to both.
This is my actualy web.config. only work with blog.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard" 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>
</system.webServer>

Redirection using web.config on wordpress website

I have issue about redirection using web.config . It is word-press website hosted on godaddy.com. Server IIS 7.0 It is window server.
I want redirect from old html page to new wordpress page.
Example:
http://www.dakshadesign.com/Ecommerce_Web_Design.html to http://www.dakshadesign.com/ecommerce-website-design-web-development-company-india/
Resloved now
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to dakshadesign.com" stopProcessing="true">
<match url="^Ecommerce_Web_Design.html$" />
<action type="Redirect" url="http://www.dakshadesign.com/ecommerce-website-design-web-development-company-india" appendQueryString="false" />
</rule>
<rule name="wordpress" patternSyntax="Wildcard">
<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>
</system.webServer>
</configuration>