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 :)
Related
I'm working on an MVC project, and I have the following working rule in my web.config, but it's redirecting all the subdomains to https. What I would like to do is to exclude some specific subdomains. For example, I need to redirect "mywebsite.com" and "www.mywebsite.com", but not "test.mywebsite.com" or "beta.mywebsite.com". The excluded subdomain should remain as "http://test.mywebsite.com" and "http://beta.mywebsite.com" without being redirected to https. How can I do that? Here's my rule in web.config:
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{REQUEST_URI}" negate="true" pattern="^/\.well-known/pki-validation/(.*)$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="true" />
</rule>
I used to have a similar configuration had used a rule along this line:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="redirect to https2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^subdomain\.example\.com$" negate="true" />
<add input="{HTTPS}" pattern="off" ignoreCase="false" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{URL}" redirectType="Found" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
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
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/
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>
I have php a website set up under IIS 7 using cakePHP. It was running for quite a while using not-so-pretty urls of the form /index.php/[controller]/[action]/[etc]. Long enough for people to have bookmarks and Google to index everything. I've now fixed the web.config so that the urls that get used are of the from /[controller]/[action]/[etc], bypassing the index.php in the url (internally it all goes to the same place).
The problem is, that if you visit one of the links in the older format, the page still technically works, but css / images / etc aren't being loaded and it looks ugly. Is there a simple way to redirect from the /index.php/* format to the new /* format?
The following is my existing web.config performing the required rewrites:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect static resources" stopProcessing="true">
<match url="^(ico|img|css|files|js)(.*)$" />
<action type="Rewrite" url="app/webroot/{R:1}{R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="/" />
</rule>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="/{R:1}" />
</rule>
<rule name="Imported Rule 4" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I worked out what I was missing. In the redirect rule, I match on /index.php/* but I didn't realize you can add the matched string into the destination using $0, $1, $2, etc. Also of note, the exactDestination="true" is necessary, otherwise it redirected /index.php/[controller]/[action]/[etc] to /[controller]/[action]/[etc]/index.php/[controller]/[action]/[etc]
I just had to add the following section to the top of the web.config (in the <system.webserver> section, before the <rewrite> section:
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Permanent">
<add wildcard="/index.php/*" destination="/$0" />
</httpRedirect>