aspnetcore-angular-universal icon indicating copy to clipboard operation
aspnetcore-angular-universal copied to clipboard

Rewrite Rules

Open curlyfro opened this issue 7 years ago • 2 comments

does anyone know how to setup rewrite rules?

curlyfro avatar Jan 22 '18 15:01 curlyfro

i need to create a serverside mvc route to dynamically create and serve PDFs. in mvc 5 i'd define my rewrite rules in web.config. how do you do this is .netcore v2, particularly this project?

curlyfro avatar Jan 25 '18 20:01 curlyfro

Just create a file rewrite-rules.xml in the root directory.

Edit startup.cs to include:

using Microsoft.AspNetCore.Rewrite;

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
    ...
   app.UseRewriter(new RewriteOptions().AddIISUrlRewrite(env.ContentRootFileProvider, "rewrite-rules.xml"));
}

And your rewrite-rules.xml should look like this:

<rewrite>
	<rules>
		<clear />
		
		<rule name="Redirect to https" stopProcessing="true">
			<match url=".*" />
			<conditions>
				<add input="{HTTPS}" pattern="off" ignoreCase="true" />
			</conditions>
			<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}?{QUERY_STRING}" redirectType="Permanent" appendQueryString="false" />
		</rule> 
   
	</rules>
</rewrite>

Flood avatar Mar 26 '18 13:03 Flood