We have ASP.NET application and set in web.config:
<rewrite>
<rules>
<rule name="RemoveTrailingSlashRule1" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
</rules>
</rewrite>
But, the trailing slash is still there.
Also, I've tried to use the code in Global.asax.cs file:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Request.Url.ToString().Contains("http://concert.local/elki/"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().Replace("http://concert.local/elki/", "http://concert.local/elki"));
}
}
But, it doesn't work as well.
The specific is "elki" is subfolder in the project and has its own web.config file that looks as following:
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="Sections.aspx" />
</files>
</defaultDocument>
<httpRedirect enabled="true" destination="/elki" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
How to make it work, that is remove trailing slash?
try removing it from the web.config ?
<rewrite>
<rules>
<rule name="Remove trailing slash" stopProcessing="true">
<match url="^([^.]+)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
</rules>
</rewrite>
Related
I'am getting error "404 Not found" when i refresh any page in my Vue JS application hosted in Azure Web APP (IIS Server) except the default web page index.html
I'am already adding this rewrite configuration in my web.config according to VueJs offical docs :
<rule name="Handle History Mode and custom 404/500" 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="/" />
</rule>
This is my web.conf file:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" 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="/" />
</rule>
<rule name="redirect all requests" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
the `router.js` file have this conf :
const router = new VueRouter({
mode: 'history',
routes: [...]
})
Any idea to resolve that ?
Regards
EDIT :
Just ADD pm2 serve /home/site/wwwroot --no-daemon --spa , in
Azure Portal > App Service > Configuration > Application Setting
Azure APP Service based on Linux , don't need to use web.config
BR.
Since I came here from top google results, and kind of kicked of my journey to get results I want to post this here in hopes it will help someone in future.
I was trying to host my Vue#3 app on local IIS to test if things work before I exchange it in production.
I am actually rewriting Vue#2 app in Vue#3, and for Vue#2 following any of these 3 links would yield success:
https://gist.github.com/AngeloAnolin/6b19d22220b27a545e10f5fa672072fa
https://www.linkedin.com/pulse/hosting-vue-js-spa-build-microsoft-iis-zainul-zain
https://dnilvincent.com/blog/posts/host-vuejs-app-on-iis
However, in Vue#3 this is a bit of overkill and will throw http error 500.19 - internal server error. Changing content of web.config with following content would yield success:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" 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="/" />
</rule>
</rules>
</rewrite>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
That's it basically. Good luck with everything :D
export default ({ childProps }) => (
<Switch>
<AuthenticatedRoute exact path={'/'} component={Home} props={childProps} />
<UnauthenticatedRoute exact path={'/login'} component={Login} props={childProps} />
<UnauthenticatedRoute path={"/autolink/:userId/:tempKey"} component={AutoLink} props={childProps} />
</Switch>
);
<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="/merchant-client" />
</rule>
</rules>
</rewrite>
Whenever I try to go to the autolink/:userId/:tempKey route it always redirects me to the home which by default loads the /merchant-client/login page.
It's weird because it works fine when I run this locally in WebStorm and GoLand, but once I had to move this to IIS it doesn't work. I had to add the URL Rewrite rule for it resolved the issue when you refresh the page it caused it to crash.
I am trying to get the IIS web.config rule rewrites to work but I have been unsuccessful thus far. Based on my research I need a single web.config file at the root of the main project.
The contents of this web.config file are as follow:
`<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<rewrite>
<rules>
<rule name="SpaRewriteRule" 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="index.html"/>
</rule>
</rules>
</rewrite>
<staticContent>
<mimeMap fileExtension=".*" mimeType="application/octet-stream" />
</staticContent>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
<environmentVariable name="COMPLUS_ForceENC" value="1" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>`
I have already installed the IIS Rewrite module. Based on this set up my expectation is that:
Once angular app is initially loaded, I would be able to refresh the page successfully - this is not the case
I have found a work around for this to add the following code in Startup.cs:
.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value) && !context.Request.Path.Value.StartsWith("/api/"))
{
context.Request.Path = "/index.html";
await next();
}
});
This however feels hacky, unless this is the accepted way of doing it now?
What is the right way of handling this?
Thanks
If you want to apply the angular routes rule which is hosted as an application and added this at the root web.config:
<rule name="ARoutes" enabled="true" stopProcessing="true">
<match url="testapi" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="http://localhost:843/testapi/index.html" logRewrittenUrl="true" />
</rule>
in short, you need to provide the full URL of the rewritten page.
and you want to use at the application level than you need to create a web.config file in the angular site dist folder.
and add below code in web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJS Routes1" enabled="true" 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>
</system.webServer>
</configuration>
Hi I would like to find out how to url rewrite.
so when the user type http://test-qa or http://test-qa.domain.com then it will redirect https url: https://test.qa.domain.com
my IISBinding
http://test-qa
http://test-qa.domain.com
Here that i have so far.
<rewrite>
<rules>
<rule name="test" stopProcessing="true">
<match url="http://test-qa" />
<action type="Redirect" url="https://test.qa.domain.com" appendQueryString="false" />
</rule>
</rules>
</rewrite>
If you prefer wildcard and assuming you only have these two bindings
<rules>
<rule name="HTTP to HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://test.qa.domain.com/{R:1}" redirectType="Temporary" />
</rule>
</rules>
In my below mentioned redirection rule I am redirecting website "fr-ca" language to "en" language except onboarding pages. That means urls should not redirect to "en" language if the urls contains onboarding pages. But it is always redirecting to "en". Please let me know what is wrong in my rule. Thanks in advance.
<rule name="Site-fr-CA to en" stopProcessing="false">
<match url="^fr-ca(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*)www.TestSite.com(.*)$" ignoreCase="false" />
<add input="{HTTP_HOST}" pattern="^fr-ca/onboarding(.*)$" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/en{R:1}" />
</rule>
</rules>
The issue is the HTTP_HOST in your second condition. Use PATH_INFO instead:
<rule name="Site-fr-CA to en" stopProcessing="false">
<match url="^fr-ca(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*)www.TestSite.com(.*)$" ignoreCase="false" />
<add input="{PATH_INFO}" pattern="^/fr-ca/onboarding(.*)$" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/en{R:1}" />
</rule>