我正在尝试将.NETCore中的一个URL重定向到另一个URL。原始URL为
http://localhost:3000/en/ad/test/1758
下面是my Startup.cs的Configure()方法。由于某种原因,就我所知,这条规则从未被遵守过。如果我把正则表达式改为
^(.*)$
当然,它每次都会成功,但对于下面的正则表达式,它就是不起作用。
为什么?
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory)
{
app.UseRewriter(new RewriteOptions().AddRedirect(@"^en/ad/.*/(\d+)$", this.Configuration["Api:PublicUrl"] + "/en/ad/$1"));
applicationLifetime.ApplicationStopping.Register(OnShutdown);
loggerFactory.AddConsole();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// Serve wwwroot as root
app.UseFileServer();
// Serve /node_modules as a separate root (for packages that use other npm modules client side)
app.UseFileServer(new FileServerOptions()
{
// Set root of file server (remember not wwwroot!)
FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "node_modules")),
// Only react to requests that match this path
RequestPath = "/node_modules"
});
}