azure web service: webconfig subdomain files rewrite - iis

Hi I have a react website with sbdomain app.mywebsite.com and I have redirected to a folder with the following rewrite in webconfig
<rule name="appRedirect" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(app\.)(.*)$" />
</conditions>
<action type="Rewrite" url="/app/{R:1}"/>
</rule>
The app works fine until I refresh the website with the url updated.
For eg. I can access app.mywebsite.com and the app will take me to app.mywebsite.com/mylink dynamically. The problem is I cannnot access the website when I access app.mywebsite.com/mylink directly.
I tried adding
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
as well but it wont work as the whole subdomain is redirected

I solved the issue by adding a webconfig file in the app directory and rewriting 404 pages to index.html
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" defaultResponseMode="File" >
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="404"
path="index.html" />
<error statusCode="500"
path="500.html" />
</httpErrors>
</system.webServer>
</configuration>

Related

IIS 10 Subdomain to folder

help me please.
I do not speak English, so I apologize if I make mistakes
in my writing (I use google translate) :(
Create my site with these features:
Bindings > *.holos.mx, holos.mx
Path > D:\Hosteos
In this directory D:\Hosteos\web.config
I have the rules:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 0" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(.*)\.holos\.mx" ignoreCase="false" />
<!--<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />-->
</conditions>
<action type="Rewrite" url="{C:1}/{R:1}" appendQueryString="true" /><!-- .php -->
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
Create this folder: D:\Hosteos\beta
Inside this folder I have another web.config. (D:\Hosteos\beta\web.config)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Imported Rule 1">
<match url="^life(|/)$" />
<action type="Rewrite" url="test.php" appendQueryString="false" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
The problem is when I enter by URL subdomains (http://beta.holos.mx/life) show error 404
When I enter URL base domain (http://holos.mx/beta/life) it shows me the content of my page test.php
How can I solve it?
You need to change URL in your rewrite action.
Your rule should be like that:
<rule name="Imported Rule 0" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(.*)\.domain\.com" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="http://holos.mx/{C:1}/{R:1}" appendQueryString="true" /><!-- .php -->
</rule>

additional paths with azure web app returns error

I made a react app using create-react-app. I am trying to deploy it on azure web app. I created a build and deployed using FTP.
When there is the internal redirect from the react the app I am able to see the webpage. But when I try to directly go to the url, I get this error.
For example:
if base url is www.example.com, and the app internally redirects to /new, the page goes to www.example.com/new. But if I directly try to load www.example.com/new, I get the above shown response. This doesn't happen in local testing
Demo:
I have created a demo here
For it to work for me, I added a web.config-file in the public-folder (this is where favicon.ico, index.html & manifest.json is located), and added the following code:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" 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="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I hope this might help :)
Place the below web.config file under the /site/wwwroot directory
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" 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="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
When there is the internal redirect from the react the app I am able to see the webpage. But when I try to directly go to the url, I get this error.
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
If you use Network tool to capture network traffic when you click the button New to render (redirect to) the new page, you will find it just changes the URL locally instead of really requesting for http://data-trigger-mass-test.azurewebsites.net/new to the server. When you directly browse and request for http://data-trigger-mass-test.azurewebsites.net/new to the server, the server could not find the resource, so it returns (404) error. In order to make the URL http://data-trigger-mass-test.azurewebsites.net/new work on both server and client-side, you may need to set up routes for it on both server and client side.
Your server should always send the root html file for all client request, so that it can pass routing to react.
If the server is NodeJs, add something like below into your server.js.
app.get('*', (req, res) => {
res.sendFile('public/index.html', { root: __dirname });
});
This worked:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" 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="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I created a web.config file in the public-folder where the index.html is located and added the above code.

IIS remove .html extension not working on folder file browse

I am trying to remove .html extensnion during the browse in iis when i browse localhost that should show index or default html that is not showing and when i browse any file in folder with extension.html as o that says HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. thought the file exist.
my web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.html" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="iisstart.htm" />
<add value="default.aspx" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Hide .html ext">
<match url="^(.*)" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}.html" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:0}.html" />
</rule>
<rule name="Redirecting .html ext" stopProcessing="true">
<match url="^(.*).html" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="(.*).html" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Please make sure you have URL Rewrite feature installed in your IIS.
see the image
If it's not available, then click on Get New Web Platform Components on right hand side, search for URL Rewrite and install it. Reopen the IIS Manager.
Click on your site and open the URL Rewrite feature. You can explore your rewrite rules which are there in web.config file. see example here

Azure Websites PHP API - 405 Method Not Allowed on PUT and DELETE

I'm building a simple PHP web service using Azure Web Sites and I'm having trouble getting it to support PUT and DELETE http methods. Assuming it's something that'll have to go into the web.config file - I've tried a few options from around the interwebs but non of them seem to function properly. Any ideas?
Here's the web.config file as it currently stands:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
</handlers>
<security>
</security>
<directoryBrowse enabled="false" />
<caching>
<profiles>
<add extension=".php" policy="DontCache" kernelCachePolicy="DontCache" />
<add extension=".html" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="14:00:00" />
</profiles>
</caching>
<rewrite>
<rules>
<rule name="block favicon" stopProcessing="true">
<match url="favicon\.ico" />
<action type="CustomResponse" statusCode="404" subStatusCode="1"
statusReason="The requested file favicon.ico was not found"
statusDescription="The requested file favicon.ico was not found" />
</rule>
<rule name="Cols Rule" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<remove value="index.php" />
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
I do not see that you have handler added into your web.config. I haven't personally tested but someone suggested that PUT and DELETE should work with Windows Azure Website however you would need to configure them correctly on your Windows Azure Websites through web.config.
Following is the simple configuration you can use to set it up:
<configuration>
<system.webServer>
<handlers>
<remove name="PHP53_via_FastCGI" />
<add name="PHP53_via_FastCGI" path="*.php"
verb="GET, PUT, POST, HEAD, DELETE"
modules="FastCgiModule"
scriptProcessor="D:\Program Files (x86)\PHP\v5.3\php-cgi.exe"
resourceType="Either" requireAccess="Script" />
</handlers>
</system.webServer>
</configuration>
It didn't work with DELETE as the last option, and here's the code modified for PHP54 on Azure. But thanks to Avkash!
<handlers>
<remove name="PHP54_via_FastCGI" />
<add name="PHP54_via_FastCGI" path="*.php"
verb="GET, PUT, POST, DELETE, HEAD"
modules="FastCgiModule"
scriptProcessor="D:\Program Files (x86)\PHP\v5.4\php-cgi.exe"
resourceType="Either" requireAccess="Script" />
</handlers>

IIS URL Rewrite 2.1 skip files that already exist

I have a URL rewrite in my web.config. The rewrite directives are intended to do two things:
If the URL refers to an actual file (such as a css file or image) don't rewrite
If the URL does not refer to an actual file, rewrite to index.php?request={R:1}
Case 2 works perfectly. However, if the requested file exists, I get a generic IIS response indicating an error: HTTP Error 500.50 - URL Rewrite Module Error. - and no other details. The error codes just indicate a generic rewrite module error.
What have I done wrong? This is IIS 10.0
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Do not rewrite existing files and folders" enabled="true" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
</conditions>
<action type="None" url="{R:0}" appendQueryString="true" logRewrittenUrl="true" />
</rule>
<rule name="Framework Parsing" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="index.php?request={R:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
<caching>
<profiles>
<remove extension=".php" />
</profiles>
</caching>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="X-Content-Type-Options" value="nosniff" />
<add name="X-Xss-Protection" value="1; mode=block" />
<add name="X-Frame-Options" value="SAMEORIGIN" />
<add name="Referrer-Policy" value="origin" />
</customHeaders>
</httpProtocol>
<!-- staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="8.00:00:00" setEtag="true" />
</staticContent -->
</system.webServer>
</configuration>
This is the error page details:
Module RewriteModule
Notification BeginRequest
Handler StaticFile
Error Code 0x80070005
Requested URL XXXXXXXXX/css/foundation/foundation.min.css
Physical Path XXXXXXXXX\public\css\foundation\foundation.min.css
Logon Method Not yet determined
Logon User Not yet determined
I notice that its login method and user is not determined.
Please try to enable anonymous authentication for your rewrite rule. And ensure IUSR have permission to access these files.

Resources