Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

.Net Core URL Rewrite - How to ignore ? inside the requested URL.

$
0
0

Hi, I have been asked at my work to remake an old website that we had been hosting since 10 year ago. I decided to use .Net Core since I'm used to it and I have been using it for quite a while now.

Sadly, the old website is in Standard ASP and was badly coded. Now having finished the website I decided to create the 301 Redirect for having good SEO when we will switch the website.

Here is what one of the old page URL look like : Old_Website.com/index.asp?s=fiche-maison&i=15146469

The reason why the URL is like that I believe is because the main index page can call upon different page with the parameters and include them into a single one. Sadly, there is one problem with that and the problem is the little "?" after index.asp

I'm using the Microsoft.AspNetCore.Rewrite middleware but when I'm trying to redirect using the rewrite option

.AddRedirect("index.asp?s=(fiche-maison)&i=(.*)", "home/fiche?inscription=$1", 301)

It doesn't work since .Net Core tries to load the page Index.Asp which causes a 404 error. I tried to fix it by changing my Option to

.AddRedirect(@"index.asp\?s=(fiche-maison)&i=(.*)", "home/fiche?inscription=$1", 301)

Using the @ and \ to change the "?" to a literal but ... it still gave me a 404 error. Am I missing something ? Thank you.

I know that the problem might be that since ? start a query string, my redirect does not occur since my browser wants to go on the page myWebsite/index.asp{QueryString}
but the thing is that I really need that to work since the company where I work makes most of its money from traffic and we don't want to lose some of it during the change of domain.

Thank you very much because I have been on this bug since the start of the day and I'm about to throw my fidget cube so hard onto the concrete wall it will turn into stardust.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>