Page 1 of 1

URL Rewrite Control

Posted: Tue Jul 28, 2009 10:21 am
by TTMedia
Hello,

I would like to have more control of the URL name of each page. Right now, the URL is created through the Product or Category Name field and I am wanting to see if it is possible to create a new field, and point the URL capture to that field.

The product and category naming and anchor text will all the same as the Name Field, but the new URL field will control what the page URL is and the link associated with the anchor text.

I don't mind the -c123.aspx suffixes, but would like to implement some more keyword rich URL's for certain products.

Thanks

Re: URL Rewrite Control

Posted: Tue Jul 28, 2009 12:10 pm
by Robbie@FireFold
I am looking for this except specifically product pages.

Re: URL Rewrite Control

Posted: Tue Jul 28, 2009 2:51 pm
by jmestep
You can try something like this, only P instead of W and pull your custom page name from somewhere. The important thing is getting the C, P, W numbers and letters in the proper place right before the .aspx

Code: Select all

HyperLink HyperLinkAlias = (HyperLink)e.Item.FindControl("HyperLinkAlias");
            HyperLinkAlias.NavigateUrl = "~/" + Regex.Replace(StringHelper.CleanupSpecialChars(_TopicAlias), "[:!;+@ ]", "-") + "-W" + _Topic.CatalogNodeId + "C" + _Topic.CategoryId + ".aspx" + "?CatId=" + CategoryId.ToString() + "&ProdId=" + ProductId.ToString();
            HyperLinkAlias.Text = _TopicAlias;

Re: URL Rewrite Control

Posted: Wed Jul 29, 2009 10:12 am
by TTMedia
Thank you,

So if I create a new field in the database and place this field in the category and product add/edit catalog backend, I can use the code to create my own custom URL's?

Re: URL Rewrite Control

Posted: Wed Jul 29, 2009 10:59 am
by jmestep
Yes, just reference that field, then follow the pattern for what I did with _TopicAlias- I turned the spaces into - and stripped out some other characters. You can actually see something like that work in the url- just go to a product page and put any text you want before the -Pxx.aspx. It will still go to the same page.

Re: URL Rewrite Control

Posted: Wed Jul 29, 2009 4:05 pm
by zxcjason
I'm wondering if there is a way to modify the NavigateUrl property of the product class, if not I suppose I'll have to add the code for each link I want to customize?

Re: URL Rewrite Control

Posted: Thu Jul 30, 2009 3:41 am
by mazhar
You can't modify NavigateUrl property. Alternatively you can write your custom function that can take Navigate Url value and process it to your desired format.

Re: URL Rewrite Control

Posted: Wed Aug 05, 2009 1:53 pm
by markpuck
I love that you can override the text in the url!

Can anybody tell me about the ~ that is stuffed into NavigateUrl? Why is it there?

If I try to use NavigateUrl with a straight <a href it keeps the ~ in the url, as in ~Foo-C10.apx, so the url doesn't work. But using the asp:Hyperlink the ~ gets stripped off.

Thanks

Re: URL Rewrite Control

Posted: Wed Aug 05, 2009 2:09 pm
by jmestep
The ~ in a <asp:hyperlink points means to use the url in relation to the root of the site. For example, if you put code in your header for a link to search.aspx and you don't do ~/search.aspx, when that header is on a checkout page the link won't work because the checkout pages are in a Checkout folder under the root of the site.

Re: URL Rewrite Control

Posted: Sat Aug 15, 2009 12:58 am
by bl108
Is there a way to have urls without the -c123.aspx suffixes, so that inbound links are protected when the catalog numbers change ?