Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 5 of 5

Thread: Changing URL Schema

  1. #1
    TomWelch is offline Member
    Join Date
    Sep 2009
    Posts
    32

    Default Changing URL Schema

    I'm trying to change my URL schema from:

    p-101-this-product.aspx

    to:

    p-101.aspx

    Does anyone know how to do this? I have found where to create the urls in the source - no problem there. It tries to use the new way to build it. I've then changed the rewrite rules for products in the web.config but I keep coming up with the same result. Even when a url is clicked on in the original format after the rule change in the web.config and it tries to go to the new URL of p-101.aspx - I get the error:

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

    Requested URL: /p-101.aspx

    Product 101 definately exists and when I change the rule back to normal the product comes up just fine. What part of this process am I missing? I'm guessing that showproducts.aspx.cs has to be changed. But I then want to do the same to Categories and Manufacturers. It seems as though this would be a pretty simple thing to change.

    Thanks,

    -Tom

  2. #2
    MarkC is offline Developer
    Join Date
    Aug 2006
    Posts
    166

    Default

    As with the format p-{product id}-{product search engine name}.aspx

    There's a logic within showproduct.aspx that checks for the SEName of the product to match with the current.
    Look for:
    C#/VB.NET Code:
    Response.Status "301 Moved Permanently"
    It then performs a 301 redirect using the current correct SEName, you'll probably have to remove that since you're not using it so as not to get redirected.

    Having the 301 redirect in place is primarily used so as to rebase to the correct/proper url and also to update search engine indexes at a later crawl point if SEName was changed after url was indexed.

  3. #3
    TomWelch is offline Member
    Join Date
    Sep 2009
    Posts
    32

    Default Changing URL Schema

    Thanks for the reply. I'm still a bit confused. Let me take this step-by-step.

    First I changed the url setup in the source in SE.MakeObjectLink, SE.MakeEntityLink and SE.MakeObjectAndEntityLink so they produce the properly formatted URLs.

    Then I changed the web.config to take these URLs and pass them with two values (instead of three) to showproducts.aspx.

    -----------------------------------------------------------------------------------------
    String SENameINURL = CommonLogic.QueryStringCanBeDangerousContent("SENa me");
    ActualSEName = SE.MungeName(DB.RSField(rs, "SEName"));
    if (ActualSEName != SENameINURL)
    {
    String NewURL = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(ProductID, ActualSEName);

    string QStr = "?";
    for (int i = 0; i < Request.QueryString.Count; i++)
    {
    string key = Request.QueryString.GetKey(i);
    if ((key.Equals("productid", StringComparison.InvariantCultureIgnoreCase)) == false && (key.Equals("sename", StringComparison.InvariantCultureIgnoreCase)) == false)
    {
    QStr += key + "=" + Request.QueryString[i] + "&";
    }
    }
    if (QStr.Length > 1)
    {
    NewURL += QStr;
    }

    HttpContext.Current.Response.Write("<html><head><t itle>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location", NewURL);
    HttpContext.Current.Response.End();
    }
    --------------------------------------------------------------------------------------

    In showproducts I found the code that you mentioned (above) and understand taking out the re-direct. But I still have the section where it finds the proper sename to contend with. I tried simply removing the entire section but I'm still getting a 404 error. Without removing that code I get an object instance error as I'm no longer passing sename.

    Any idea what I'm doing wrong? There seems to be an integral piece in this that I'm just not getting. I'm sure it's going to be a V8 moment when I figure it out - LOL!

    Thanks,

    -Tom

  4. #4
    MarkC is offline Developer
    Join Date
    Aug 2006
    Posts
    166

    Default

    Did you remove the whole block or just a line or two?
    I was able to get it working by ripping out the whole redirect block and modified the rewrite rule in web.config

    Code:
    <!--<rule url="/p-([0-9]*)-([\w-]*)\.aspx(?:\?(.*))?" rewrite="/showproduct.aspx?ProductID=$1&amp;SEName=$2&amp;$3" />-->
    <rule url="/p-([0-9]*).aspx(?:\?(.*))?" rewrite="/showproduct.aspx?ProductID=$1&amp;" />

  5. #5
    TomWelch is offline Member
    Join Date
    Sep 2009
    Posts
    32

    Default All fixed

    Thanks very much! Your suggestions were very helpful! The last thread was what I needed. I was using the rewrite rule incorrectly. I plugged in your rule and it worked on the first try.

    For those who would like to this-

    To remove sename from your product page URLs follow these steps:

    1.
    Change your web.config rewrite rule for products from:

    <rule url="/p-([0-9]*)-([\w-]*)\.aspx(?:\?(.*))?" rewrite="/showproduct.aspx?ProductID=$1&amp;SEName=$2&amp;$3 " />

    to:

    <rule url="/p-([0-9]*).aspx(?:\?(.*))?" rewrite="/showproduct.aspx?ProductID=$1&amp;" />

    2.
    Remove the following redirect block from showproducts.aspx.cs:

    HttpContext.Current.Response.Write("<html><head><t itle>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location", NewURL);
    HttpContext.Current.Response.End();

    3.
    In the source (ASPDNSFCore::SE), change MakeObjectLink and MakeObjectAndEntityLink to create a two part URL ({0}-{1}.aspx) instead of three ({0}-{1}-{2}.aspx).

    Now you should have a URL for your product pages that reads:

    www.your-site/p-150.aspx
    instead of:
    www.your-site/p-150-your-product.aspx

    -Tom