Question

I'm using http://urlrewriter.net/ to rewrite urls at my website. For example, I'm rewriting:

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 to dynamically add the meta tag:

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

only to the page that hasn't been rewritten. This is because I want both URLs to work, but only the rewritten one to be indexed by search engines.

How do I determine which version of the page has been requested?

EDIT

Answers below suggest a 301 redirect instead of using a meta tag. Maybe I'll do this, but I still want to know the answer to the underlying question... how do I know if the page has been rewritten?

Was it helpful?

Solution

personally, I would 301 redirect from the un-rewritten one to the re-written one, and only use the single copy of the page. It is easier for users, and from an SEO perspective, you have 1 copy of the content.

OTHER TIPS

If you need to do this you can probably do something like:

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

And you can check for the header in your view and add the robots meta tag if you need it.

This will get returned to the client too, so if you want to hide that you can write a CustomAction (http://urlrewriter.net/index.php/support/reference/actions/custom-action) which will set some kind of state value in your request.

However, having two URIs for the same resource is something I would not recommend. I suggest you just keep the one representation. If you're worried about invalidating old bookmarks you can set the old one to redirect to the new one.

Further to chakrit's answer, it looks like UrlRewriter.NET stores the original URL in the HttpContext, in a key called UrlRewriter.NET.RawUrl. So, you could try something like:

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

Most obvious method is to use the Request.Url object in your page to get information about the URL and query string. For example:

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

I think that's the job of HttpContext.Current.Items.

You can save the "Redirection" in HttpContext.Current.Items and then in your pages, you can check it for a certain added value.

I believe you can add hooks to urlrewriter.net that could do it, something alongs:

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

And then in your webpages, you could check it by:

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top