Print Page | Close Window

Rewrite away PC's sub-directories

Printed From: ProductCart E-Commerce Solutions
Category: ProductCart
Forum Name: Search Engine Optimization
Forum Description: Talk about ways to optimize your ProductCart store for search engines
URL: https://forum.productcart.com/forum_posts.asp?TID=3390
Printed Date: 11-May-2024 at 7:34pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Rewrite away PC's sub-directories
Posted By: Guests
Subject: Rewrite away PC's sub-directories
Date Posted: 30-January-2010 at 1:27am
I've been working on this on an off for far too long, but as any of you who may work with regex and ISAPI_Rewite know, it's not easy to nail things down . . . even the folks at Helicon typically have to make several trial and error attempts to get things right.

So, I am really happy to announce that with a mere 5 lines of conditions/rules we've successfully "rewritten away" the top two sub-directories PC enforces so that all of your site content resolves to the web root!Some developers may find it desirable not to have to use these two sub-directories and would rather have the store resolved right in the web root of the domain.

However, to do this, you must have a host that provides Helicon's ISAPI_Rewrite (which is awesome for lots of other issues too) -- so you must have a VPS or dedicated server plan where you can install things on the server yourself, such as ISAPI_Rewrite. Shared hosting plans are not likely to offer this option unless you are with a "boutique" host such as Grey Beard Design Group or Web Merchant Services.

If you have the option to use ISAPI_Rewrite, here is the code you will want to use in your .htaccess or httpd.ini file in your web root:

# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.42

RewriteEngine on
RewriteBase /

# START: Mask the /productcart/pc/ directory structure and make all such URLs look like they are in the web root
# Handle image directories as they are otherwise referenced from the web root:
RewriteRule ^(images/.*|catalog/.*)$ productcart/pc/$1 [NC,L]
RewriteRule ^(UPSLicense/.*|CAPTCHA/.*)$ productcart/$1 [NC,L]

# Handle javascrits as they are otherwise reference above the web root:
RewriteRule ^(includes/.*)$ productcart/$1 [NC,L]

# Handle objects called via ../pc/ when already in the /pc/ folder:
RewriteRule ^pc/(.*)$ productcart/pc/$1 [NC,L]

# Permanently redirect all pages that were using subdirectories:
RewriteRule ^productcart/pc/(.*)$ $1 [NE,NC,R=301,L]

# Handle having all pages resolve in the web root without subdirectories:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ productcart/pc/$1 [NC,L]
# END: Mask the /productcart/pc/ directory structure and make all such URLs look like they are in the web root

What's more, if you would find it desirable to maintain the first sub-directory as a way of adding some key word relevance to your URLs, the script can be easily adapted to provide for that.

Finally, it's possible that you may have customized some things in your design differently than this set up rules will handle. If that is the case you should maybe be able to follow the example above, but if not and you have trouble with the regex, please PM me.

PS: This post is not intended to make any claim that rewriting away the sub-directories would improve SEO. The options here are provided as just that: options so that you can make your own decisions on how best to SEOptimize your store.
 

EDIT: Correct for v4 One Page Checkout -- added handling for the JQuery and Spry subdirectories.

EDIT: Simplified rules for the previous edit -- should have just done it like this in the first place, LOL!

EDIT: Just confirmed that this full set of conditions and rules will NOT work with versions of ISAPI_Rewrite prior to 3.1.0.43. Curent version as of 02/12/2010 is 3.1.0.69

EDIT: Fixed a minor wrinkle with location of UPS logo in v4 OPC

EDIT: Fixed a minor wrinkle with location of CAPTCHA images

EDIT: Simplified the conditions to anything that gets put into the /productcart/includes/ folder

EDIT: Added fix introduced by v4.1 calling objects by ../pc/ when already in the /pc/ folder



Replies:
Posted By: blackey
Date Posted: 31-January-2010 at 1:42pm
Sean,

Very, Very cool.  Does not seem to work with 4.0 checkout though.  Worked on all the pages and cart, but the onepagecheckout.asp page would not allow me to check in.

Thoughts?

Bill


Posted By: blackey
Date Posted: 31-January-2010 at 2:00pm
If you could have this ignore https pages, I think it would work with the checkout.  I tried it with the https off, and that works fine.  Not sure if the code below is the most elegant, but it works. 

I think having the checkout not rewriten is a good idea anyway.  That way everyone's Analytics will not need to be re-written, etc...  Plus search engines shouldn't spider those pages anyways.

The cannonical link can be easily modified to not return the directories.




# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.42

RewriteEngine on
RewriteBase /

# START: Mask the /productcart/pc/ directory structure and make all such URLs look like they are in the web root
# Handle image directories as they are otherwise referenced from the web root:

RewriteCond %{HTTPS} off
RewriteRule ^(images/.*|catalog/.*)$ productcart/pc/$1 [NC,L]

# Handle javascrits as they are otherwise referenced above the web root:
RewriteCond %{HTTPS} off
RewriteRule ^(includes/javascripts/.*)$ productcart/$1 [NC,L]

# Permanently redirect all pages that were using sub-directories:
RewriteCond %{HTTPS} off
RewriteRule ^productcart/pc/(.*)$ $1 [NC,R=301]

# Handle having all pages resolve in the web root without sub-directories:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ productcart/pc/$1 [NC,L]
# END: Mask the /productcart/pc/ directory structure and make all such URLs look like they are in the web root



Posted By: Guests
Date Posted: 01-February-2010 at 2:16pm
Hi Bill,
 
I see I needed to add handling for the JQuery and Spry directories used in the OPC. I've edited the original post to handle that.
 
This would probably be the way to go for new stores, but I hear what you are saying about existing stores wanting to switch this up. Your solution, to condition out HTTPS would be the way to go there.


Posted By: whizzinpc
Date Posted: 01-February-2010 at 7:42pm
Great Stuff Guys! Wish this was here a year ago before we did our url changes to the 404 method.


Posted By: Guests
Date Posted: 01-February-2010 at 9:14pm
Thanks, @whizzinpc, but just to be clear to everyone, this has nothing to do with PC's 404-based URL rewriting. That rewriting handles "pretty" URLs rather than the default query string based URLs.

This is a different level of rewriting to mitigate against the two top level sub-directories. It changes nothing about whether the page level is query string based or bounced of the custom 404 error handling method.


Posted By: blackey
Date Posted: 06-February-2010 at 8:25pm
Sean,

I've been implementing this and have found Google indexing the following:

www.lpiracing.com/store/pc/store/pc

It's rewriting the store/pc and removing it, but if there are multiples it removes all of them.  I'd like this to return a 404.  I've been trying to figure out how to keep it form doing this, but so far it's eluding me.




Posted By: Guests
Date Posted: 06-February-2010 at 9:37pm
Hi @blackey,
 
I'm afraid I don't quite understand you question. Are you saying that you have a directory structure with http://www.lpiracing.com/racing-parts/pc/ - www.lpiracing.com/racing-parts/pc/  as well as http://www.lpiracing.com/racing-parts/pc/racing-parts/pc/ - www.lpiracing.com/racing-parts/pc/racing-parts/pc/  -- or that somehow Google indexed things this way?
 
Had a spin through your site, clicking from pages Google had indexed and everything appear to be all good.
 
Please explain further what you are up against here.


Posted By: blackey
Date Posted: 07-February-2010 at 11:19am
Yea sorry about that.  The real directory is store/pc.  Unfortunately, store/pc/store/pc will rewrite to the same page.  Google has picked up on Store/pc/store/pc and I've seen some pages being spidered that way.


Posted By: Guests
Date Posted: 08-February-2010 at 1:30pm

So, are you saying that you want to use this to rewrite /store/pc/store/pc/ back to just /store/pc/ and not have the pages re-written back to the web root?



Posted By: blackey
Date Posted: 08-February-2010 at 2:33pm
RewriteRule ^productcart/pc/(.*)$ $1 [NC,R=301]

The rewrite above is causing the productcart/pc/productcart/pc to be valid.  It could be productcart/pc repeating 1000 times for that matter and the way the above rewrite works it would still be valid.  Google picks up on that and indexes all kinds of connonical pages.  I think the rewrite should include the base url somehow to cause multiples of productcart/pc to go to a 404 page.






Posted By: Hamish
Date Posted: 08-February-2010 at 2:46pm
Hi Blackey,
     There's an entry on the WIKI for adding a canonical tag to ProductCart.
I understand Google finds pages by following links etc - so I'm unclear how it can find variations on URL's that are not linked to anywhere, so are there links to "productcart/pc/productcart/pc"versions of your pages?


-------------
Editing ProductCart Code?

See http://wiki.earlyimpact.com/developers/editcode" rel="nofollow - WIKI Guidelines for Editing ProductCart's ASP Source Code



Posted By: Guests
Date Posted: 08-February-2010 at 2:58pm
Originally posted by blackey blackey wrote:

RewriteRule ^productcart/pc/(.*)$ $1 [NC,R=301]
The rewrite above is causing the productcart/pc/productcart/pc to be valid.  It could be productcart/pc repeating 1000 times for that matter and the way the above rewrite works it would still be valid.  Google picks up on that and indexes all kinds of connonical pages. 
Not exactly. While productcart/pc/productcart/pc/ would still resolve, anything there has been permanetly (301) redirected to the same file in the root. So such "legacy" URLs are not infact "valid", they are 301 redirected. This tells Google "this page has been permantly moved, so drop indexing on the old location and reindex under the new location," essentially.
 
Originally posted by blackey blackey wrote:

I think the rewrite should include the base url somehow to cause multiples of productcart/pc to go to a 404 page.
 
Why throw a 404 when you can 301 redirect?
 
So, I'll try once more: Do you want your store pages to resolve under the web root, or are you looking to correct pages indexed as /productcart/pc/productcart/pc/* back to just /productcart/pc/?


Posted By: blackey
Date Posted: 08-February-2010 at 3:53pm
Sean,

I have the cannonical link, and Google is still indexing multiple productcart/pc/productcart/pc/ pages (as seen from Smarterstats).  Not sure if they will show up in the serps that way yet, but I've seen them do it before even with 301's.  What Google should do, and what they do are not always the same I've found.

I would prefer that store/pc resolves, but store/pc/store/pc does not.




Posted By: Guests
Date Posted: 08-February-2010 at 9:31pm
Hi @blackey,
 
If that's the case, this isn't really the regex you should be using for your purpose; your issue is different than what we are trying to address here on this thread.
 
Something like this should work for you, though:

RewriteEngine on
RewriteBase /

# START: redirect double /productcart/pc/ sud-directories back to /productcart/pc/
RewriteRule ^productcart/pc/productcart/pc/(.*)$ /productcart/pc/$1 [NC,R=301,L]
 
If that doesn't work for you, please take up your issue on Helicon's ISAPI_Rewrite forum. Anton over there will get you ironed out. I don't presume to support ISAPI_Rewrite issues in general here on this forum; only the very specifi PC issues I've chosen to address. The issue I'm addressing on this thread is to rewite away the typical PC sub-directory strucuture, not any anomolies you may already have existing on your site as legacy.


Posted By: intour
Date Posted: 19-March-2010 at 12:39pm
This looks really neat Sean,
 
If it gets rid of the 2 levels productcart displays how does it display the page name?
 
Does is work with the SEO friendly URL's? so for example:
 
mysite.com/productcat/pc/myproduct.htm
 
becomes
 
mysite.com/myproduct.htm
 
Nigel
 
 


-------------
http://www.innerview.co.uk - Innerview
Productcart Platinum Reseller
Web Design/Hosting/Virtual Tours


Posted By: blackey
Date Posted: 19-March-2010 at 1:01pm
Here is an example:

http://www.lpiracing.com/



Posted By: intour
Date Posted: 19-March-2010 at 1:55pm
Thanks Blackey,
 
I like this !
 
Nigel


-------------
http://www.innerview.co.uk - Innerview
Productcart Platinum Reseller
Web Design/Hosting/Virtual Tours


Posted By: Guests
Date Posted: 03-April-2010 at 12:09am
I have found one little issue more here with regard to the location of UPS logos. I have edited the original post to account for this.


Posted By: Guests
Date Posted: 07-April-2010 at 2:47pm
I have found one more little issue more here with regard to the location of CAPTCHA images. I have edited the original post to account for this.


Posted By: Guests
Date Posted: 05-June-2010 at 1:17am
I ran into another JavaScript issue today. The issue was with PCa SP4 when a sub-product was set to change the price if this option were selected when using the drop-down select option for display. On the client side, any of the options set this way would not appear.

For example:

Color: Blue | Red
Size: Small | Large (+1.00)

In this scenario, "Large (+$1.00)" will not show in either color.

I've updated the rules and conditions posted on the first post of this thread.


Posted By: blackey
Date Posted: 06-June-2010 at 1:19pm
Sean,

Have you noticed multiple Custom search fields not working.  I can do one, but when I add a second it crashes.  Works fine with the rewrite off.

Bill



Posted By: Brett
Date Posted: 06-June-2010 at 5:35pm
# Permanently redirect all pages that were using sub-directories:
RewriteRule ^store/pc/(.*)$ $1 [NE,NC,R=301,L]


If you add NE to that line, it should work.


Posted By: Guests
Date Posted: 23-September-2010 at 6:06pm
Ok, v4.1 introduced a new thing to deal with here. In several places there are calls to JavaScripts and such:


<link type="text/css" rel="stylesheet" href="../pc/ei-tooltip.css">

<script language="javascript" type="text/javascript" src="../pc/ei-tooltip.js"></script>

<script type="text/javascript" src="../pc/XHConn.js"></script>


This causes a problem with the ISAPI_Rewrite script I've been using, as the page is already in the /pc/ folder but src looks up the the /productcart/ folder and then back down to the /pc/ folder again. This is a problem when we've rewritten away the /productcart/ and /pc/ folders. I've added this to the origin post here.


# Handle objects called via ../pc/ when already in the /pc/ folder:
RewriteRule ^pc/(.*)$ productcart/pc/$1 [NC,L]


Posted By: ProductCart
Date Posted: 23-September-2010 at 7:28pm
Originally posted by Sean@WMS Sean@WMS wrote:

Why when the page is already in the /pc/ folder the src looks up the the /productcart/ folder and then back down to the /pc/ folder where you are already are is beyond me...


The reason is that the same code is used in the Control Panel as well. For example, when you add a product to an order via the Edit Order feature, you are using a lot of code that is included into the Control Panel files, but actually resides in the pc folder. This is done to avoid code duplication (the product details page alone, for example, means a lot of code that would have to be duplicated).


-------------
The ProductCart Team

Home of ProductCart http://www.productcart.com" rel="nofollow - shopping cart software


Posted By: Guests
Date Posted: 23-September-2010 at 7:48pm
Originally posted by earlyimp earlyimp wrote:



Originally posted by Sean@WMS Sean@WMS wrote:

Why when the page is already in the /pc/ folder the src looks up the the /productcart/ folder and then back down to the /pc/ folder where you are already are is beyond me...
The reason is that the same code is used in the Control Panel as well. For example, when you add a product to an order via the Edit Order feature, you are using a lot of code that is included into the Control Panel files, but actually resides in the pc folder. This is done to avoid code duplication (the product details page alone, for example, means a lot of code that would have to be duplicated).


AH! I see, said the blind man as he picked his hammer and saw. Now that makes sense. I was scratching my head on that one.


Posted By: Guests
Date Posted: 08-November-2012 at 4:03pm
Thought I should add on to this the method for doing this in IIS 7 with the URL Rewrite extension installed.

First of all, the URL Rewrite extension must be installed in IIS. Download it here:
http://www.iis.net/downloads/microsoft/url-rewrite" rel="nofollow - http://www.iis.net/downloads/microsoft/url-rewrite

The rules can then be added to the <system.webServer> section:
<rewrite>
    <rules>
        <clear />
        <rule name="Imported Rule 18" stopProcessing="true">
            <match url="^(images/.*|catalog/.*|custom/.*|Library/.*|tax/.*)$" />
            <action type="Rewrite" url="productcart/pc/{R:1}" />
        </rule>
        <rule name="Imported Rule 19" stopProcessing="true">
            <match url="^(UPSLicense/.*|CAPTCHA/.*)$" />
            <action type="Rewrite" url="productcart/{R:1}" />
        </rule>
        <rule name="Imported Rule 20" stopProcessing="true">
            <match url="^(includes/.*)$" />
            <action type="Rewrite" url="productcart/{R:1}" />
        </rule>
        <rule name="Imported Rule 21" stopProcessing="true">
            <match url="^productcart/pc/(.*)$" />
            <action type="Redirect" url="{R:1}" redirectType="Permanent" />
        </rule>
        <rule name="Imported Rule 22" stopProcessing="true">
            <match url="^([^/]+)$" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            </conditions>
            <action type="Rewrite" url="productcart/pc/{R:1}" />
        </rule>
        <rule name="Imported Rule 23" stopProcessing="true">
            <match url="^pc/(.*)$" />
            <action type="Rewrite" url="productcart/pc/{R:1}" />
        </rule>
</rules>
</rewrite>



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net