Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2010
    Posts
    362
    Plugin Contributions
    0

    Default Help with Rewrite Rules

    As I've mentioned earlier, Google is for some reason incorrectly indexing some of my product urls, leaving out the cPath designation.

    While I try to find out why, I figured I could at least set up some rewrites so that the bad Google links can be redirected correctly.

    I've spent a couple of hours trying to figure out how to create a correct Rewrite Rule for the .htaccess file -- and I've failed miserably. So, if any of you super code types have a second, can you look at what I have and let me know where I've gone wrong?

    What I want to do is redirect this url:
    index.php?main_page=product_info&products_id=1

    To this:
    index.php?main_page=product_info&cPath=1&products_id=1

    And he's what I've come up with, which I've placed in a .htaccess file in the /store directory


    RewriteEngine On
    RewriteRule ^index.php?main_page=product_info&products_id=1$ index.php?main_page=product_info&cPath=1&products_id=1 [R=301,L]

    It does absolutely nothing -- no errors, but no redirects.

    Sorry, I know I'm being a lame coder here, but I'm guessing someone on this site will know the answer to this.

    Thanks,

    John

  2. #2
    Join Date
    Jan 2004
    Location
    N of San Antonio TX
    Posts
    9,686
    Plugin Contributions
    11

    Default Re: Help with Rewrite Rules

    I'm not sure that making matters worse is going to be of any help. Out of the box, ZC has never confused Google. As a matter of fact, several of our customers are outperforming the "home" company without rewrites and the elusive SEO.

    How about answering the posting tip questions so that we can see if something you have installed is part of the problem. Also, it's always good to give us a look at the site. If you don't want it to be instantly available on the SEs, give us the URL as yoursiteDOTcom or similar.
    A little help with colors.
    myZenCartHost.com - Zen Cart Certified, PCI Compatible Hosting by JEANDRET
    Free SSL & Domain with semi-annual and longer hosting. Updating 1.5.2 and Up.

  3. #3
    Join Date
    Dec 2010
    Posts
    362
    Plugin Contributions
    0

    Default Re: Help with Rewrite Rules

    Well, I'll try, but there have been so many modifications to this setup that I'm not sure I'll be able to list them.

    We're using ZC 1.3.9h, upgraded from 1.3.9a. The 1.3.9a version was heavily modified by the former developer. As far as I know, there are no plugins that relate to SEO or search engine friendly URLs -- at least none that I can see in the admin interface.

    I don't know how long the problem has been in existence -- the client has been working the Google angle lately and discovered it, but it may have been there all along.

    I have searched the forums and FAQ for similar issues -- have not found anything.

    The site url is: http://www.quinceandco.com

    If you want to see the issue I'm referring to, google "quince and co chickadee" -- you'll get this url:

    http://quinceandco.com/store/index.p...&products_id=1

    The "correct" url (the one you get if you follow the path to the product from the home page of the site is:

    http://quinceandco.com/store/index.p...&products_id=1

    As you can see, the missing element is &cPath=1.

    This issue appears to exist for all Google searches of the site's products -- the cPath information is not included in the Google url.

    Let me know if there's anything else I can supply for info.

  4. #4
    Join Date
    Aug 2005
    Location
    Vic, Oz
    Posts
    1,905
    Plugin Contributions
    5

    Default Re: Help with Rewrite Rules

    1.3.9 and more recent use "canonical links"
    Use view source on the page and you will see what the link is, that is passed to google as the "correct" link.
    As products can be in multiple linked categories, the category is NOT included in the canonical link.
    Otherwise you could end up with many, many links pointing to the same product, which are duplicate content.

    So... In summary... The correct product link is without the path.
    So... Its working correctly as it is.

  5. #5
    Join Date
    Dec 2010
    Posts
    362
    Plugin Contributions
    0

    Default Re: Help with Rewrite Rules

    Ah, well thank you for clearing that up. At least I know why.

    But here's the problem -- the original developer uses conditional formatting on the product info page based on the cPath that's passed in the link. No cPath and the user gets a generic page that is not formatted correctly.

    So, what's the purpose of a canonical link and is it possible to either disable this function, or better yet, modify it so that it includes the cPath?
    Last edited by jgold723; 9 Aug 2013 at 11:54 AM.

  6. #6
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,845
    Plugin Contributions
    25

    Default Re: Help with Rewrite Rules

    Quote Originally Posted by jgold723 View Post
    Ah, well thank you for clearing that up. At least I know why.

    But here's the problem -- the original developer uses conditional formatting on the product info page based on the cPath that's passed in the link. No cPath and the user gets a generic page that is not formatted correctly.

    So, what's the purpose of a canonical link and is it possible to either disable this function, or better yet, modify it so that it includes the cPath?
    Normally the formatting by Cpath should still work.

  7. #7
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Help with Rewrite Rules

    Quote Originally Posted by jgold723 View Post
    ...
    RewriteEngine On
    RewriteRule ^index.php?main_page=product_info&products_id=1$ index.php?main_page=product_info&cPath=1&products_id=1 [R=301,L]

    It does absolutely nothing -- no errors, but no redirects.
    ...
    You cannot match "query terms" (everything after the ? in the URL) by using just RewriteRule. You need to use RewriteCond statements along with a RewriteRule. This is a common mistake made by novice users of Apache mod_rewrite. If you really really really must use a redirect... I'd recommend reading the mod_rewrite documentation from Apache or doing some searches for how to match "query terms" with mod_rewrite.

    Quote Originally Posted by jgold723 View Post
    ... But here's the problem -- the original developer uses conditional formatting on the product info page based on the cPath that's passed in the link. No cPath and the user gets a generic page that is not formatted correctly. ...
    It sounds like you want some extra template code to always be inserted into the page when a product is in a certain "category"... if this is correct, adding an additional (and unnecessary) redirect does not seem like the best solution...

    If you want to match based upon master category:
    You can get the product's master category id by using the built in Zen Cart function zen_get_products_category_id($product_id)...
    If you need the entire cPath, you can use the built in Zen Cart function zen_get_product_path($products_id)...

    If you want to match based upon the parent category:
    You can use a SQL query to obtain the parent category id for the product...
    If you need the entire cPath use the built in Zen Cart function zen_get_generated_category_path_rev($categories_id)...
    Last edited by lhungil; 10 Aug 2013 at 08:07 PM.
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  8. #8
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Help with Rewrite Rules

    Note: For most pages $cPath and $current_category_id are already defined (and can be directly used in templates). This would be the simplest way unless modifications to your Zen Cart installation have been made which alter (or break) these two global variables.
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  9. #9
    Join Date
    Aug 2005
    Location
    Vic, Oz
    Posts
    1,905
    Plugin Contributions
    5

    Default Re: Help with Rewrite Rules

    Quote Originally Posted by lhungil View Post
    Note: For most pages $cPath and $current_category_id are already defined (and can be directly used in templates). This would be the simplest way unless modifications to your Zen Cart installation have been made which alter (or break) these two global variables.
    Hmmm. As google sees and stores the direct canonical link to the product.
    Then when someone clicks on the google link they also go direct to the product.
    Maybe then $cPath is NOT defined?
    or maybe it points to the master category, (I must check when I have some time)
    So conditional formatting that relies on a correctly defined $cPath may NOT work correctly.
    The op may need to consider some default formatting for this situation.

  10. #10
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Help with Rewrite Rules

    Quote Originally Posted by gilby View Post
    Hmmm. As google sees and stores the direct canonical link to the product.
    Then when someone clicks on the google link they also go direct to the product.
    Maybe then $cPath is NOT defined?
    or maybe it points to the master category, (I must check when I have some time)
    So conditional formatting that relies on a correctly defined $cPath may NOT work correctly.
    The op may need to consider some default formatting for this situation.
    For product pages I believe $cPath is set to the master product category using zen_get_product_path($products_id). See init_category_path.php.

    If the OP needs the parent category (mostly affects linked products), they will most likely need to take a look at doing what is mentioned in "match based upon the parent category" above.
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

 

 

Similar Threads

  1. Replies: 0
    Last Post: 24 Sep 2013, 04:32 PM
  2. help url rewrite in the IIS7.0?
    By jjyypi in forum All Other Contributions/Addons
    Replies: 3
    Last Post: 7 Jul 2010, 11:15 AM
  3. .htaccess rewrite with folders and Private SSL?
    By littlehawk in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 14 Sep 2009, 07:10 PM
  4. Add Rewrite Rules to Apache?
    By mcleanmell2 in forum General Questions
    Replies: 5
    Last Post: 18 Mar 2009, 12:57 AM
  5. Homepage works, other pages give 404 - problem with SEO mod and rewrite rules
    By Nimbuz in forum Templates, Stylesheets, Page Layout
    Replies: 15
    Last Post: 20 Jan 2008, 02:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg