views:

536

answers:

5

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?

+2  A: 

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.

jonnii
+1  A: 

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
DannySmurf
I'm not sure if this will work with urlrewriting.net, as the rewriting translates the url back to normal format for the application to use.
Mitchel Sellers
+2  A: 

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.

Mitchel Sellers
That's definitely an option, but I want to also explore the nofollow option.
Keltex
ALso, be sure to keep in mind that if the unwritten page has page rank, using no follow will loose that page rank and hide the page. If you use 301 it will transfer.
Mitchel Sellers
That's a good point. I think my question is still relevant. How do I determine if the request is for the rewritten page? If not rewritten then I 301.
Keltex
A: 

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.

chakrit
A: 

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"]);
cxfx