ASPX templates
Version 5.x > ASPX templates > URL Rewrite possibilities View modes: 
User avatar
Member
Member
Jimmy - 2/22/2011 8:53:25 PM
   
URL Rewrite possibilities
We have a database with a few thousand products in it. That database contains product names, descriptions, images, pricing information etc. and we've built an an ASPX template that displays the details of any particular product.

Obviously, with so many products, we don't really want to create a node in the kentico site structure for each product... and presently the only "key field" for each product is an Identity field in SQL server. As such, at the moment the URL for our product page looks something like this:
http://localhost/product?ProductID=422

Clearly not super SEO friendly.

What I'm wondering is if we could maybe link to a URL like the following:
http://localhost/product/blue_widgets/422

Where "blue_widgets" was the name of the product - we wouldn't actually use that portion of the url in any way - it wouldn't correspond to a document in the Kentico site structure... it would simply be for SEO purposes to better describe the document that was being returned.

Is that possible?

Thanks in advance.
Jimmy

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 2/23/2011 10:36:02 AM
   
RE:URL Rewrite possibilities
Hello,

You could use wildcards for this. For example there would be a page with the URL www.domain.com/products. You could define two wildcards e.g. {productname}/{productid}. In that case, if you access the page with the following URL:

www.domain.com/products/new_produuct/45

you will be redirected correctly to your page:

www.domain.com/products

Now you have only to get the URL and check for the wildcards to configure your repeaters.

Best regards,
Boris Pocatko

User avatar
Member
Member
Jimmy - 2/23/2011 11:33:50 AM
   
RE:URL Rewrite possibilities
Awesome... too easy! Thanks Boris.

Now I just have to make sure that multiple urls can't be used for the same product. With the Document URL path "/product/{productname}/{productid}" I can now enter either of the following to load product 422 using this template:
http://localhost/product/foo/422
http://localhost/product/bar/422

If Google finds the product using both of those urls somehowe, the page might incur a duplicate content penalty.

I'm guessing that should be pretty easy to work around. I figured I'd just have code in the template that checked the URL that was used in the Request and issued a 301 redirect if it didn't match the pattern specified by the Document URL path (which I can presumably get at via the Kentico API).

However, I'm wondering if this is the right approach. From what I recall, when viewing the document in CMSDesk kentico won't use the same URL as when it gets requested on the live site, right? Is there perhaps an additoinal check I need to make to see whether the document is being requirested from within CMSDesk or not before doing any redirects?

TIA.

Kind Regards,
Jimmy

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 3/2/2011 9:44:51 AM
   
RE:URL Rewrite possibilities
Hello,

If you check the "Redirect document aliases to main URL" in CMSSiteManager / Settings / URLs and SEO, then this should behave as expected. All requests are redirected to the main URL, so the file will be accessible, but formaly you will access always only one resource.

Best regards,
Boris Pocatko

User avatar
Member
Member
Jimmy - 3/2/2011 10:38:18 AM
   
RE:URL Rewrite possibilities
Forgive me, but I fail to see how it possibly could. How would Kentico even know what the correct URL should be if I was using wildcards in the URL?

I have one template and one page using that template with the Document URL path "/product/{productname}/{productid}". I have thousands of products in our inhouse database that might potentially be displayed using this page template and urls such as the following:

http://localhost/product/blue_widgets/422
http://localhost/product/green_widgets/422
http://localhost/product/red_widgets/422

All of the above three URLs clearly point to the same product (the product ID for all three is 422) but how would Kentico possibly know which was the correct {productname} to use be used in the URL and thus whether it should redirect requests for http://localhost/product/blue_widgets/422 to http://localhost/product/green_widgets/422 or vice versa?

Surely this must require I write some code which looks up the actual product name from our inhouse databases and does the redirect manually (unless Kentico ships with Psychic powers included :-) In this case then, where/how is it safe for me to implement this code such that I won't break the template in CMSDesk (when it certainly won't be requested using the SEO friendly URL that my code would be redirecting to)?

Thanks in advance.

Kind Regards,
Jimmy

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 3/7/2011 3:03:49 AM
   
RE:URL Rewrite possibilities
Hello,

I am sorry for the confusion. You are of course right. Especially if you are using some custom database.

You will need to ensure the correct behavior on the webpart level by modifying/creating a new webpart. If you are only modifying the webpart, then you don't need to check if it's in the CMSDesk or on the live site. You will need to check what combination of {productName} and {productId} is correct and do a redirect if necessary.

Best regards,
Boris Pocatko

User avatar
Member
Member
Jimmy - 3/7/2011 3:10:55 AM
   
RE:URL Rewrite possibilities
Webpart? But this is an ASPxTemplate and Kentico doesn't support WebParts in ASPxTemplates I don't think does it?

Also, how would putting it in a webpart avoid having the redirect occur when viewing the page in CMSDesk (I can certainly get the redirect working... but I don't want to redirect all the time - only when viewing the page on the live site - not when editing)?

Maybe I'm mising something really obvious so sorry if this question seems elementary.

TIA

Jimmy

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 3/15/2011 12:07:44 PM
   
RE:URL Rewrite possibilities
Hello,

The aspx approach supports webparts. You can place a webpart onto an aspx page by navigating to the webparts folder and drag and dropping the webpart onto your page. An example can be found on our Sample Corporate ASPX site in the file "CMSTemplates\CorporateSiteAspx\Offices.aspx" (please note the WebPartContainer tag).

I am a bit confused on the redirect conditions here. I assumed, you want to check those links inside a webpart which displays those links (e.g. a repeater). In that case you would need to modify this webpart to check the links against your database. Anyway, if you want to do this test by default on a page, then you can place a webpart (or control) on it to check the links (requests). This check can be also implemented in the Global.asax.cs file, in the Application_BeginRequest method, which is called everytime a new request enters the application. To check if your site is in design mode you can either check the URL or the ViewMode cookie if available:

using CMS.CMSHelper;
...
ViewModeEnum currentMode = CMSContext.ViewMode;

switch (currentMode)
{
case ViewModeEnum.Edit:
//you are in the edit mode
break;
case ViewModeEnum.LiveSite:
//you are on the live site
break;
}

Best regards,
Boris Pocatko