How to determine if the asp.net url has been "rewritten"?

I use http://urlrewriter.net/ to rewrite the URLs on my site. For example, I rewrite:

http://www.example.com/schedule.aspx?state=ca

to

http://www.example.com/california.aspx

What I'm trying to do (for SEO purposes) to add a meta tag dynamically:

<meta name="robots" content="noindex,follow" />

only to a page that has not been rewritten. This is because I want both URLs to work, but only rewritten for indexing by search engines.

How to determine which version of the page was requested?

EDIT

The answers below suggest a 301 redirect instead of a meta tag. Maybe I'll do it, but I still want to know the answer to the main question ... how do I know if the page has been rewritten?

+3
5

, 301 . , SEO 1 .

+2

, - :

<add header="X-WasRewritten" value="true" />

, .

, , , CustomAction (http://urlrewriter.net/index.php/support/reference/actions/custom-action), - .

URI - , . . , , .

+2

chakrit-, , UrlRewriter.NET URL- HttpContext UrlRewriter.NET.RawUrl. , - :

bool isPageRewritten = 
   !string.IsNullOrEmpty(HttpContext.Current.Items["UrlRewriter.NET.RawUrl"]);
+2

Request.Url URL- . :

if (Path.GetFileName(Request.Url.FilePath) == "schedule.aspx")
   //Not rewritten
else
   //rewritten
+1

, HttpContext.Current.Items.

"" HttpContext.Current.Items, .

, urlrewriter.net, , - :

HttpContext.Current.Items["Redirected_From"] = currentUrlHere;

And then on your web pages you can check this:

if (!string.IsNullOrEmpty(HttpContext.Current.Items["Redirected_From"]))
    // the page been redirected, do something!
else
    // no it visited normally.

I have long left it for the ASP.NET Routing platform in .NET 3.5 SP1, which is better than urlrewriter.net IMO.

0
source

Source: https://habr.com/ru/post/1699069/


All Articles