which web.config to use in AspNetBoilerplate startup template? - aspnetboilerplate

Downloaded a free startup template and got a zip archive with the whole solution.
When unzipping the archive on windows I got a message asking whether to overwrite existing web.config file.
And indeed there are two web.config files below /src/myapp.Web.Host/.
The two file names differ in upper/lower case of the first letter.
One is named Web.config and the other web.config and the content differs.
Which one shall I use?
Options used:
ASP.NET Core 2.x
Target Framework: .NET Core (Cross Platform)
SPA with Angular
Include login, ...
One Solution

Until the issue fixes, you can use this web.config content...I tried, works perfectly.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<!-- ASPNET CORE SETTINS -->
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore
processPath="%LAUNCHER_PATH%"
arguments="%LAUNCHER_ARGS%"
stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="false"
startupTimeLimit="3600"
requestTimeout="23:00:00" />
<!-- REMOVE INFO LEAK HEADERS -->
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<!-- MIME TYPES -->
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
<mimeMap fileExtension="woff" mimeType="application/font-woff" />
<mimeMap fileExtension="woff2" mimeType="application/font-woff" />
</staticContent>
<!-- IIS URL Rewrite for Angular routes -->
<rewrite>
<rules>
<rule name="Angular 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>
https://github.com/aspnetboilerplate/aspnetboilerplate/files/2149283/Web.config.zip

Related

How to Rewrite URL in Tomcat 9

Just wanted to know how to rewrite the URL in Tomcat. previously we use to use IIS to rewrite the URL and not we have moved to Tomcat 9.
In ISS We have created web.config file and created a rewrite map.
In Web.config file script was written as
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<remove name="Redirect rule1 for Login_Redirect" />
<rule name="Rewrite rule1 for AdobeRewriteMap">
<match url=".*" />
<conditions>
<add input="{AdobeRewriteMap:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
<rewriteMaps>
<remove name="Login_Redirect" />
<remove name="AdobeRewriteMap" />
<rewriteMap name="AdobeRewriteMap">
<add key="/updateforms" value="<adobe URL>" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer>
</configuration>
Now we would like the implement the same in tomcat. Can anyone help me out to achieve the same functionality in Tomcat 9.
Thanks,
VJ.
we would like the implement the same in tomcat. Can anyone help me out to achieve the same functionality in Tomcat 9.

Web.config images not showing

My web.config looks like the below:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<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>
<httpErrors errorMode="Detailed" />
When I try to request an image in a sub-folder I'm getting a error:
HTTP Error 500.50 - URL Rewrite Module Error.
If I change the line:
<match url="*" />
to
<match url=".*" />
Then the image displays, but the rewrite for my laravel app in the root directory doesn't work and gives a 404 error.
I need to change the web.config so that both the laravel app and the images work.
You should try:
<match url="^" />

How to remove index.php in codeigniter on Windows Server and IIS?

How to remove index.php in codeigniter on Windows Server and IIS?
I found this when i search for answer
How to rewrite the index.php of Codeigniter on Windows Azure
but when i try my CI still need index.php to run
whre the web.config file must be add and is there any other step before i edit my web.config?
If URL Rewrite module is not installed, please install it from here http://www.iis.net/downloads/microsoft/url-rewrite
Please check the complete web.config file. Place this in the same folder where the index.php is placed.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<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>
</rules>
</rewrite>
</system.webServer>
</configuration>
Its working in IIS in Windows server 2008 R2
This answer is a little more secure (paranoid) than the others, and is based on the way CakePHP does it. This assumes that you have a directory named "public" which contains all of the js, css, image, and font files. If you have other extensions you want to allow, add them to the second rule. You can change the directory name from "public" to anything be replacing the word "public" in rule 1 and 2.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Exclude direct access to public/*" stopProcessing="true">
<match url="^public/(.*)$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets by extension" stopProcessing="true">
<match url="^(.*)(\.(css|js|otf|eot|svg|ttf|woff|woff2|jpg|png|gif|ico))$" />
<action type="Rewrite" url="public/{R:1}{R:2}" appendQueryString="false" />
</rule>
<rule name="Rewrite requested file/folder to index.php" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Make web.config put in the root directory.
User code:
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
<rewrite>
<rules>
<rule name="RuleRemoveIndex" 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" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true"/>
</rule>
</rules>
</rewrite>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
You should upload the web.config file with your project and write the code
web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<rewrite>
<rules>
<rule name="Hide Yii Index" 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" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If You are still getting the problem then go through the following link
PHP MVC Framework IIS index.php solution

IIS rewrite not working for simple redirects

All I want to do is 301 redirect from old URLs to new URLs:
from /xx/yy/somefile.html to /xx/yy/somefile.aspx
some examples below:
add key="/products/DSD-72B-SP-summary.html" value="/products/DSD-72B-SP-summary.aspx"
add key="/products/DSD-72B-SP-detail" value="/products/DSD-72B-SP-detail.aspx"
add key="index.html" value="default.aspx"
add key="/product-selector.html" value="/products.aspx"
That is all but it doesn't seem to want to work in IIS 7.5 with URL rewrite 2.0.
I have tried at least 10-20 different rules, and rewrite map formats without any luck.
In fact I have done this so many times I have had to wipe the rules and maps from IIS and totally recopy a web.config file from a backup to unscrew what I screwed with to try and make it work.
All I need is a simple rule that tells IIS that if it gets a request for a *.html file to display the *.aspx file that replaced the html file.
<?xml version="1.0" encoding="UTF-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings configProtectionProvider="DataProtectionConfigurationProvider">
<EncryptedData>
<CipherData>
</CipherData>
</EncryptedData>
</appSettings>
<connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
<EncryptedData>
<CipherData>
</CipherData>
</EncryptedData>
</connectionStrings>
<system.web>
<customErrors mode="On" defaultRedirect="404-NotFound.aspx">
<error statusCode="404" redirect="404-NotFound.aspx" />
<!--<error statusCode="403" redirect=""/>-->
</customErrors>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
<!--<codeSubDirectories>
<add directoryName="CSharp"/>
<add directoryName="VB"/>
</codeSubDirectories>-->
</compilation>
<authentication mode="Forms">
</authentication>
<membership>
<providers>
<clear />
</providers>
</membership>
<profile>
<providers>
<clear />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
<defaultDocument>
<files>
</files>
</defaultDocument>
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404-NotFound.aspx" responseMode="ExecuteURL" />
</httpErrors>
<tracing>
<traceFailedRequests>
<add path="*">
<traceAreas>
<add provider="WWW Server" areas="Rewrite" verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="200-500" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
</configuration>
Make sure you clear your cache too. Sometimes you can update a server rule but your browser will continue to show the old page.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Vanity URL" enabled="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{MAPNAME:{PATH_INFO}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MAPNAME">
<add key="/products/DSD-72B-SP-summary.html" value="/products/DSD-72B-SP-summary.aspx" />
</rewriteMap>
</rewrite>
</system.webServer>
</configuration>
The above code it taking directly from my website with minor name changes for generality and added in your page. Try to remove other rules and isolate the issue.

Remove index.php of Codeigniter on IIS?

I understand I can remove the 'index.php' part of the url with the following web.config code:
<rewrite>
<rules>
<rule name="Rule" 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/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Problem is I have CI installed in a sub-directory (mydomain.com/codeigniter) and I'm having trouble understanding the web.config file.
Do you know how to change this so it works for a sub-directory?
I have WordPress in the root directory and my CodeIgniter application in a sub-directory. I create a similar web.config like yours and save it in the sub-directory. My CI app doesn't need the index.php in url any more.
At first, I add my sub-directory in the <action url="myapp/index.php/{R:1}"...> and wish it could be restricted to look into the sub-directory only but fails. I remove the sub-directory and leave it to original but move the web.config to the subdirectory and it works.
Therefore, I think maybe you may create two web.config files with different rules and saves them in different directory.
Another note might help: enable the error message to output the detail from IIS. I use the tricks to find out how IIS looks for my files. It is <httpErrors errorMode="Detailed" />, <asp scriptErrorSentToBrowser="true"/>, and the <system.web> section as below:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
<rewrite>
<rules>
<rule name="RuleRemoveIndex" 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" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true"/>
</rule>
</rules>
</rewrite>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
</configuration>
Make web.config put in the root directory.
User code:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
<rewrite>
<rules>
<rule name="RuleRemoveIndex" 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" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true"/>
</rule>
</rules>
</rewrite>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>

Resources