Some SEO optimizations

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 15 ans
The this that is bugging me is the way URLs are displayed.
Now the URLs for categories and products are like this:
- http://www.yourstore.com/Category/id-category-name.aspx
- http://www.yourstore.com/Product/id-product-name.aspx
But to optimize even more you can alter the settings and code in nopCommerce so you display the URLs even more nicely, like this:
- http://www.yourstore.com/categoryId-categoryName.aspx
- http://www.yourstore.com/categoryId-categoryName/productId-productName.aspx
You'll be asking why keep the id's for both categories and products. Because nopCommerce won't recognize the virtual path.

So the modifications are as follows:
1. In the admin area go to Configuration > Global settings > SEO/Display and set the Product and Category URL rewrite format as:
- product: {0}{1}-{2}/{3}-{4}.aspx
- category: {0}{1}-{2}.aspx

2. In the URLConfig.config from the nopCommerce web app modify the product and category rewrite rules like this:

    <add name="ProductDetailsRewrite" virtualUrl="^~/([0-9]*)-([\w-]*)/([0-9]*)-([\w-]*)\.aspx(?:\?(.*))?"
         rewriteUrlParameter="ExcludeFromClientQueryString"
         destinationUrl="~/Product.aspx?ProductID=$3&amp;$4"
         ignoreCase="true" />


    <add name="CategoryDetailsRewrite" virtualUrl="^~/([0-9]*)-([\w-]*)\.aspx(?:\?(.*))?"
     rewriteUrlParameter="ExcludeFromClientQueryString"
     destinationUrl="~/Category.aspx?CategoryID=$1&amp;$2"
     ignoreCase="true" />

*I don't know if the $4 and $2 from the destinationUrls are useless so I left them there. They are the product and category names

3. In code go to nopCommerce solution > Libraries > Nop.Common > SEO > SEOHelper.cs and replace the GetProductURL method with

public static string GetProductURL(int ProductID)
{
    Product product = ProductManager.GetProductByID(ProductID);
    if (product == null)
        throw new NopException(string.Format("Product couldn't be loaded. ID={0}", ProductID));
    string seName = GetSEName(product.SEName);
    if (String.IsNullOrEmpty(seName))
    {
        seName = GetSEName(product.Name);
    }

    //jkr - seo optimization
    //get the category and display it in the product url
    //1. get the bottom most category - be sure to give the categories DisplayOrders don't leave them as "1"
    Category category = CategoryManager.GetCategoryByID(product.ProductCategories[product.ProductCategories.Count - 1].CategoryID);
    //2. if the category id and name are by some misterious ways null just display "Category" - haven't tested it so if it's not correct don't complain
    int catId = 0;
    string catName = "Category";
    if (category != null)
    {
        //else save the id and name
        catId = category.CategoryID;                
        catName = GetSEName(category.Name);
    }
    
    //so you don't get an error in the format
    string url = string.Format(SettingManager.GetSettingValue("SEO.Product.UrlRewriteFormat"), CommonHelper.GetStoreLocation(false), category.CategoryID, catName, ProductID, seName);
    return url;
}


If you have other SEO optimizations please let the community know about them :)
Il y a 14 ans
Good thinking, jkr.

I have done it a bit different though.
I use the following pattern for my products
{0}{2}-p{1}.aspx

Mainly for 2 reasons:
1. In this case I have more permanent urls. So if I decide to rename the category or move my product under another category url stays the same and I don't get penalized for duplicated urls
2. Google likes flat urls by giving first level urls more weight. also keywords closer to the beginning of url get more value, that's why i moved id to the end.
Il y a 14 ans
by the way here is rewrite rule if somebody is interested

    <add name="ProductDetailsRewrite" virtualUrl="^~/([\w-]*)-p([0-9]*)\.aspx(?:\?(.*))?"
       rewriteUrlParameter="ExcludeFromClientQueryString"
       destinationUrl="~/Product.aspx?ProductID=$2&amp;$3"
       ignoreCase="true" />
Il y a 14 ans
Hi,
When created some topic in version 1.20 i got source

<div class="htmlcontent-title">
<span id="ctl00_ctl00_cph1_cph1_ctrlHomePageText_topicHomePageText_lblTitle">My Home Page</span>
</div>

Question. Where it create tag <span>? (in code Modules/TopicPage we can see <asp:Label>)
Thanks
Il y a 14 ans
label is transformed to html span by .net
Il y a 14 ans
Yes i know, just i need optimize website.
I need to replace the span.
I want to see <h1> instead of <span>
Maybe you know where it`s in the code?
Thx
Il y a 14 ans
alexlin wrote:
Yes i know, just i need optimize website.
I need to replace the span.
I want to see <h1> instead of <span>
Maybe you know where it`s in the code?
Thx


instead of using a label use a literal. this acts like a label (well it outputs text) but you can't assign a css class to it and it won't render as a span .
so you can have in your aspx something like

<h1>
<asp:Literal id="litTitle">My home page</asp:Literal>
</h1>


you can also replace the <div class=".."> with <h1> so you don't have to change the code from label to literal (if the text is set in code).
Il y a 14 ans
AB Fitness wrote:
Good thinking, jkr.

I have done it a bit different though.
I use the following pattern for my products
{0}{2}-p{1}.aspx

Mainly for 2 reasons:
1. In this case I have more permanent urls. So if I decide to rename the category or move my product under another category url stays the same and I don't get penalized for duplicated urls
2. Google likes flat urls by giving first level urls more weight. also keywords closer to the beginning of url get more value, that's why i moved id to the end.


Thanks for the info.
When i decided to make my urls look that way (category/product) i knew that i wouldn't be changing them. in theory they can be changed, but in practice i don't think so (at least for my app). But i've forgot about the id's and your suggestion is quite good... move the id last.
Il y a 14 ans
Hi jkr,
I tried it yesterday
Not work. Debugger sayd me what Literal it`s not type Label and i got
<span> in source code.
  
Do you know where it rewrite in the code?
Also body of topic it place in span
============
[quote]
<span id="....">
<p>
Some text of topic created in admin side
</p>
</span>

[/quote]

  
Excuse me for my bad English
Il y a 14 ans
don't just rename from asp:Label to asp:Literal. now you need to go into the .designer.cs and find the line that looks like
protected global::System.Web.UI.WebControls.Label litTitle;

and change it to
protected global::System.Web.UI.WebControls.Literal litTitle;

for the lblBody just delete the label, place a literal on the form, name it litBody (or something), go to code (F7) and replace lblBody with litBody.
[quote]Do you know where it rewrite in the code?
Also body of topic it place in span[/quote]
i assume you're referring to Topic.ascx which you'll find in \Modules\
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.