IIS 10 Subdomain to folder - .htaccess

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>

Related

URL Rewrite Module 2.1 redirection http to https not working

They changed the url rewrite Module version (URL Rewrite Module 2.1) and now the redirection from http to https is not working.
Has anyone encountered the same problem?
Application : Angular
System : Windows Server IIS 10
This is the web.config file (it was working for the earliest version of URL rewrite : urlrewrite2.exe)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<fileExtensions applyToWebDAV="false">
<add fileExtension=".pdf" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
<directoryBrowse enabled="true" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<rewrite>
<rules>
<rule name="redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Thanks.
For http://example.com:80 to https://example.com:443 your rule posted in the question is correct and working fine on my side.
If it is not working on your side, you could check the Failed Request Tracing logs might give you the information about the issue. The issue might be something else.
For http://example.com:81 to https://example.com:443, you could refer to the rule below.
<rule name="Redirect with port" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*):81$" />
</conditions>
<action type="Redirect" url="https://{C:1}:443/{R:0}" />
</rule>
Output:
Let me know if you have further questions.

Font files not loading in Drupal site running in Azure Server

Here's a font file that resides in the server. But it seems to be throwing 404
And here's the web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<!-- Don't show directory listings for URLs which map to a directory. -->
<directoryBrowse enabled="false" />
<!--
Caching configuration was not delegated by default. Some hosters may not
delegate the caching configuration to site owners by default and that
may cause errors when users install. Uncomment this if you want to and
are allowed to enable caching.
-->
<!--
<caching>
<profiles>
<add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
<add extension=".html" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="14:00:00" />
</profiles>
</caching>
-->
<rewrite>
<rules>
<rule name="Protect files and directories from prying eyes" stopProcessing="true">
<match url="\.(engine|inc|install|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format|composer\.(json|lock)|\.htaccess)$" />
<action type="CustomResponse" statusCode="403" subStatusCode="0" statusReason="Forbidden" statusDescription="Access is forbidden." />
</rule>
<rule name="Force simple error message for requests for non-existent favicon.ico" stopProcessing="true">
<match url="favicon\.ico" />
<action type="CustomResponse" statusCode="404" subStatusCode="1" statusReason="File Not Found" statusDescription="The requested file favicon.ico was not found" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
</rule>
<!-- To redirect all users to access the site WITH the 'www.' prefix,
http://example.com/foo will be redirected to http://www.example.com/foo)
adapt and uncomment the following: -->
<!--
<rule name="Redirect to add www" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://www.example.com/{R:1}" />
</rule>
-->
<!-- To redirect all users to access the site WITHOUT the 'www.' prefix,
http://www.example.com/foo will be redirected to http://example.com/foo)
adapt and uncomment the following: -->
<!--
<rule name="Redirect to remove www" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://example.com/{R:1}" />
</rule>
-->
<!-- Pass all requests not referring directly to files in the filesystem
to index.php. -->
<rule name="Short URLS" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
<!-- If running Windows Server 2008 R2 this can be commented out -->
<!-- httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/index.php" responseMode="ExecuteURL" />
</httpErrors -->
<defaultDocument>
<!-- Set the default document -->
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
Site is running in an Azure Server. And my guess is that it is because of some rewrite rules, which am not able to figure out. Any inputs would be highly appreciated.
Try adding MIME Maps for the static content.
ie, after the </defaultDocument>, add the following lines:
<staticContent>
<mimeMap fileExtension=".woff2" mimeType="application/x-font-woff" />
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<mimeMap fileExtension=".json" mimeType="application/json" />
<mimeMap fileExtension=".css" mimeType="text/css" />
</staticContent>

IIS 10 - JSON files are not serving even after configured MIME and Handlers

I have deployed a web application in IIS 10 (Windows 10) build from Node.
Files structure
I am unable to access the JSON files (for eg., http://localhost:3000/manifest.json) using the direct URL.
Receiving the following error,
I have set MIME Type as follows,
I have tried the Handler Mapping too,
My web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Static Assets" stopProcessing="true">
<match url="([\S]+[.](html|htm|svg|js|css|png|gif|jpg|jpeg|json))" />
<action type="Rewrite" url="/{R:1}" />
</rule>
<rule name="ReactRouter Routes" stopProcessing="true">
<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="/index.html" />
</rule>
</rules>
</rewrite>
<handlers>
<add name="StaticFileModuleJson" path="*.json*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
</handlers>
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
I notice that your rewrite rule have rewritten .json to .js. It has nothing to do with the handler because static file hanlder is still handling the request.
Please swap the index of js and json.
<rule name="Static Assets" stopProcessing="true">
<match url="([\S]+[.](html|htm|svg|json|css|png|gif|jpg|jpeg|js))" />
<action type="Rewrite" url="/{R:1}" />
</rule>

Add .html to url in Azure web.config rewrite

I am looking to use the sub-page link for a website on Azure, for example:
Html file mysubpage.html placed in the wwwroot directory in Azure. I wish to be able to access this page by typing mysite.com/mysubpage into the web browser. However, when I visit this url I get the output "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
I understand that I need to do this with a web.config file in the wwwroot directory, but am unsure as to what contents the web.config file needs to contain?
I currently have the following:
<?xml version="1.0" ?> <configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Rule">
<match url=".*" />
<conditions>
<add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" />
</rule>
<rule name="Remove html Extension" stopProcessing="true">
<match url="^(.+)\.html$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="StaticRewrites" defaultValue="">
<add key="/mysubpage" value="/mysubpage.html" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer> </configuration>
Solved the issue. The following worked which removed the removal of the html extension:
<?xml version="1.0" ?> <configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Rule">
<match url=".*" />
<conditions>
<add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="StaticRewrites" defaultValue="">
<add key="/mysubpage" value="/mysubpage.html" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer> </configuration>
I understand that it you want to re-route numerous urls you can do this by adding extra lines with add as follows:
<add key="/mysubpage1" value="/mysubpage1.html" />
<add key="/mysubpage2" value="/mysubpage2.html" />

IIS rewrite rule not working on Azure

I have a URL rewrite rule to redirect from non-www to www. But a non-www address just gives a 404 error.
Anyone spot the problem? The site is hosted on Azure.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation batch="false" />
<customErrors mode="off"/>
</system.web>
<system.webServer>
<handlers>
<add name="iisnode" path="keystone.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="FilanthropyStar">
<match url="/*" />
<action type="Rewrite" url="keystone.js" />
</rule>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^filanthropystar.org$" />
</conditions>
<action type="Redirect" url="http://www.filanthropystar.org/{R:0}"
redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Resources