Glossary Item Box

Squirrelcart v6.1.0

URLs

Overview

Squirrelcart allows you to control the format of your URLs that link to products, categories, and other pages. We will refer to this feature with the term SEO URLs, (SEO stands for Search Engine Optimized). Here are 4 examples of product page URLs based on how you have your SEO URL settings configured: 

Query String URL: (OK)

http://www.example.com/store.php?crn=180&rn=279&action=show_detail

This method has data in the URL that helps Squirrelcart determine what to show your customer. That data is only meaningful to your web server.

 

Search Engine Optimized URL: (better!)

http://www.example.com/store.php/products/deluxe-bookshelf/

This method removes the query string data and replaces it with more meaningful information. If this page was indexed in a search engine, searching for "deluxe bookshelf" is more likely to generate a result linking to this page.

 

Search Engine Optimized URL - Advanced: (much better!)

http://www.example.com/products/deluxe-bookshelf/

This method is identical to the previous one with the exception that the storefront page is no longer present (store.php by default). 

 

Search Engine Optimized URL - Advanced: (best!)

http://www.example.com/furniture/deluxe-bookshelf/

This method is identical to the previous one with the exception that the category, product, and content bases are not used. When viewing a product, it is preceded by a base matching it's category for better SEO. Category and content URLs are not prefixed with any base, and the storefront page is no longer present (store.php by default). 

For this setup, enable SEO URLs, then follow the steps under SEO URLs (Advanced) below, and be sure to check the Smart Bases checkbox.

Query String URLs

Requirements:

None 

Setup Instructions:

We recommend using SEO URLs when possible. If your server doesn't support them, here's how to configure Squirrelcart to use query string URLs.

  1. Open the SEO and Metadata Settings page.
  2. Change the URL Format field in the General fieldset to query string:
    search engine settings 
  3. Click Save Changes

SEO URLs

Requirements:

Your server must support the $_SERVER['PATH_INFO'] variable OR support both the $_SERVER['SCRIPT_NAME'] and $_SERVER['REQUEST_URI'] variables.

Precautions:

When enabling SEO URLs, you are changing the URL structure for Squirrelcart content.  Because of this, any code you've written yourself in your storefront must use absolute URLs. If you are using relative URLs in your Squirrelcart storefront, those URLs will not be valid. This will result in broken links, broken images, etc...

See the Broken Images and Links section at the end of this page for more information.

  

Overview

Enabling SEO URLs will turn your URLs from something like this:

http://www.example.com/store.php?crn=180&rn=279&action=show_detail

 

To this:

http://www.example.com/store.php/products/deluxe-bookshelf/

 

Setup Instructions:

  1. Open the SEO and Metadata Settings page.
  2. Locate the General fieldset. Towards the top of that fieldset, click the Click here link to check your server for SEO URL support:
  3. This will open the SEO URL test page:
    seo diag page
  4. Click the link labeled "Click here to perform test".
    seo url test
  5. If the test passed, you will see the message above and can continue to the next step. If you do not see this message, your server does not support PATH_INFO and you should stop here. If you contact your webhost, they may be able to add support for PATH_INFO for you.
  6. Change the URL Format field in the General fieldset to search engine optimized:
    search engine settings
  7. A new section will appear labeled URLs.
    SEO URL settings

    The fields in this section control certain aspects of your URLs. You can leave the defaults and skip to the next step. If you prefer to change these settings, here is what each one does:

    Category Base
    This is the part of your category URLs that precede the name of the category. The default value for this is "categories", which would be used in a category URL as follows:

    http://www.example.com/store.php/categories/books


    Product Base
    This is the part of your product URLs that precede the name of the product. The default value for this is "products", which would be used in a product URL as follows:

    http://www.example.com/store.php/products/coffee-table


    News Base
    This setting is only present when the News module installed. This is the part of your news URLs that precede the name of a news post. The default value for this is "news", which would be used in a news post URL as follows:
    store.php/news/2008/11/25/post-name

    http://www.example.com/store.php/news/2008/11/25/post-name


    News Archives Base
    This setting is only present when the News module installed. This is the part of your news URLs that represents the term "archives". The default value for this is "archives", which would be used in your news archives URL as follows:

    http://www.example.com/store.php/news/archives


    Reviews Base
    This setting is only present when the Reviews module is installed. This is the part of your review URLs that precede the name of the product. The default value for this is "reviews", which would be used in a review URL as follows:

    http://www.example.com/store.php/reviews/product-name


    Reviewer Base
    This setting is only present when the Reviews module is installed. This is the part of your reviewer URLs that precede the record number of the reviewer. The default value for this is "reviewer", which would be used in a reviewer URL as follows:

    http://www.example.com/store.php/reviews/reviewer-382


    Testimonials Base
    This setting is only present when the Testimonials module is installed. The default value for this is "testimonials", which would be used in your testimonials page URL as follows:

    http://www.example.com/store.php/testimonials


    Contact Base
    This setting is only present when the Contact module is installed. The default value for this is "contact", which would be used in your contact page URL as follows:

    http://www.example.com/store.php/contact


    Downloads Base
    This setting is only present when the Download Delivery module is installed. The default value for this is "downloads", which would be used in your download page URL as follows:

    http://www.example.com/store.php/downloads


    Store Locator Base
    This setting is only present when the Store Locator module is installed. The default value for this is "store-locator", which would be used in your store locator page URL as follows:

    http://www.example.com/store.php/store-locator


    Content Base
    The default value for this is "content", which appears in links to your own pages (via content records) as follows:

    http://www.example.com/store.php/content/about-us


    Page Base
    This is the part of your URLs that represents the term "page", used in links to additional pages. The default value for this is "page", which would be used in a URL as follows:

    http://www.example.com/store.php/categories/books/page-4


    Smart Bases
    When checked, product, category, and content bases are not used.

    Category URLs for products that are in a category will appear with the category name as a base. Example:

    http://www.example.com/books


    Product URLs for products that are in a category will appear with the category name as a base. Example:

    http://www.example.com/books/gone-with-the-wind


    Product URLs for products that are not in a category will appear using just the product name base. Example:

    http://www.example.com/gone-with-the-wind


    Content URLs (links to non store pages) will appear using just the link name base. Example:

    http://www.example.com/about-us


    With Smart Bases enabled, if you also enable No Filename, you must use Method 1 in the SEO URLs (Advanced) steps towards the bottom of this page.



    Space Character
    This controls the default character used in place of a space in your URLs. The default value for this is "hyphen":

    http://www.example.com/store.php/products/this-is-a-long-product-name


    Setting this to "underscore" would make the above URL look like this:

    http://www.example.com/store.php/products/this_is_a_long_product_name


    No Filename
    This field can be checked to remove the storefront page name from most of your URLs.
    Do not check this field without following the instructions in the Setting up SEO URLs (advanced) section below!
  8. Click Save Changes

 

Customizing

You can control how product, category, and news post names appear in your URLs by modifying the SEO URL Name field in each respective table in your control panel. Here's an example of this field on a category record.

  

Redirects

If a user tries to load a page using a query string URL after you have enabled SEO URLs, Squirrelcart will issue a redirect (HTTP code 301) to the equivalent SEO URL. This will ensure search engines know the page has moved to a different location, and help to avoid penalties for duplicate content.

 

If you decide to change the SEO URL Name field for a particular item (see Customizing section directly above), and a URL is requested using the prior value you had stored in that field, Squirrelcart will issue a redirect to the new URL.

 

Example: Using the image above, the URL to the "Compact Discs" category is:

http://www.example.com/store.php/categories/compact-discs

 

Now, 3 months after that page has been indexed by a search engine you decide to change your URL to this by changing the SEO URL Name field to cds

http://www.example.com/store.php/categories/cds

 

If the old URL is requested by a user, they will automatically be redirected to the new URL.

SEO URLs (advanced)

Overview

This is an additional procedure you can follow to remove the storefront page from your URLs after you've followed the steps above to enable SEO URLs. This is an advanced topic, and caution should be taken when attempting this procedure.

This will change your URLs from something like this:

http://www.example.com/store.php/products/coffee-table

To this:

http://www.example.com/products/coffee-table

 

 With the Smart Bases feature enabled, you can get even nicer URLs that don't use the category, product, and content bases:

http://www.example.com/furniture
http://www.example.com/furniture/coffee-table
http://www.example.com/about-us



 

Requirements

 

Setup Instructions Explained 

There are 3 ways to handle this. All require .htaccess file support. The first two methods uses mod_rewrite, and the second uses either ForceType or SetHandler directives. Follow the section below that corresponds to what your server has support for. If you aren't sure, we recommend you follow the mod_rewrite instructions first. If they do not work, then try the "ForceType/SetHandler" instructions.

 

Method 1 (recommended): Setup Instructions Using Mod_Rewrite, Giving Squirrelcart Full Control

Mod_Rewrite is a feature built into Apache web servers that allows you to transform the URL requested by a client into a different URL without the client seeing their URL change in their browser. With this method, when the customer requests a URL like:

http://www.example.com/products/coffee-table

Mod_Rewrite will change their request to include your storefront page without changing the URL in their browser: 

http://www.example.com/store.php/products/coffee-table

This method will send all page requests for any folder or file that does not actually exist on your server to Squirrelcart, in turn giving Squirrelcart full access to just about any URL. If you want to use the Smart Bases feature (highly recommended), you will need to use this method.

  1. Follow the instructions above in the section titled Setting up SEO URLs
  2. Create a blank file with the name .htaccess in the same folder that contains your storefront page.
  3. Using a text editor, paste the following code into your blank .htaccess file:

    RewriteEngine On

    # This tells the rule to NOT redirect to index.php if request is for a directory that exists
    RewriteCond %{REQUEST_FILENAME} !-d

    # This tells the rule to NOT redirect to index.php if request is for a file that exists
    RewriteCond %{REQUEST_FILENAME} !-f

    # This tells the rule to NOT redirect if the request had an extension other than .php
    RewriteCond %{REQUEST_URI} \.php|/[^\.]*$ [NC]

    # All other requests redirected to index.php
    RewriteRule ^(.*)$ store.php/$1 [L]

  4. If you've renamed your storefront page from it's default name of store.php, change that string from "store.php" to your actual storefront page name.
  5. Save the file
  6. Try loading your storefront page in a browser to confirm that your .htaccess file is not causing any errors. If you receive an Internal Server error, you either have a typo in your htaccess file OR your server doesn't support mod_rewrite. If you believe the problem is the latter, stop here and try the instructions further down labeled "Instructions Using ForceType/SetHandler".
  7. Try loading the following URL (changing the domain name in the example to match yours):

    http://www.example.com/products/


    If you receive a page looking like your storefront page but with a red 404 error in the center, then the process worked. The 404 error appears because you aren't linking to a specific category. If you receive an Internal Server Error, your server probably doesn't support mod_rewrite - stop here and try the instructions below for ForceType/SetHandler.
  8.  Now that you have your .htaccess file configured and working properly, you just need to tell Squirrelcart to remove the storefront page from the URLs that it generates. To do this, check the No Filename field on your Store Settings page, in the section labeled SEO URLs. With this configuration you can also enable the Smart Bases option in the same section. If you enable either of these, click the "save changes" button.
  9. You're done! Head to your storefront page and click your product and category links to make sure they are working OK.

    

Method 2: Setup Instructions Using Mod_Rewrite, Giving Squirrelcart Partial Control

Mod_Rewrite is a feature built into Apache web servers that allows you to transform the URL requested by a client into a different URL without the client seeing their URL change in their browser. With this method, when the customer requests a URL like:

http://www.example.com/products/coffee-table

Mod_Rewrite will change their request to include your storefront page without changing the URL in their browser: 

http://www.example.com/store.php/products/coffee-table

If you want to use the Smart Bases feature (highly recommended), you cannot to use this method. See method 1 above.

  1. Follow the instructions above in the section titled Setting up SEO URLs
  2. Create a blank file with the name .htaccess in the same folder that contains your storefront page.
  3. Using a text editor, paste the following code into your blank .htaccess file:

    RewriteEngine On
    RewriteRule ^(products|categories|content|news|reviews|testimonials|contact|downloads|store-locator|auth)/?(.*)$ store.php/$1/$2 [L]

  4. If you've renamed your storefront page from it's default name of store.php, change that string from "store.php" to your actual storefront page name.
  5. Save the file
  6. Try loading your storefront page in a browser to confirm that your .htaccess file is not causing any errors. If you receive an Internal Server error, you either have a typo in your htaccess file OR your server doesn't support mod_rewrite. If you believe the problem is the latter, stop here and try the instructions further down labeled "Instructions Using ForceType/SetHandler".
  7. Try loading the following URL (changing the domain name in the example to match yours):

    http://www.example.com/products/


    If you receive a page looking like your storefront page but with a red 404 error in the center, then the process worked. The 404 error appears because you aren't linking to a specific category. If you receive an Internal Server Error, your server probably doesn't support mod_rewrite - stop here and try the instructions below for ForceType/SetHandler.
  8.  Now that you have your .htaccess file configured and working properly, you just need to tell Squirrelcart to remove the storefront page from the URLs that it generates. To do this, check the No Filename field on your Store Settings page, in the section labeled SEO URLs and click the "save changes" button.
  9. You're done! Head to your storefront page and click your product and category links to make sure they are working OK.

  

Method 3: Setup Instructions Using ForceType/SetHandler

ForceType is a directive you can use in an htaccess file to force a file to be treated as a particular MIME type regardless of it's file extension. This method works by tricking your server into serving files named "products" and "categories" (with no file extension) into opening as PHP files. These file names will look just like directory names in your URLs, and your customers won't know that they are actually PHP pages.

  1. Follow the instructions above in the section titled Setting up SEO URLs
  2. Create a blank file with the name .htaccess in the same folder that contains your storefront page.
  3. Using a text editor, paste the following code into your blank .htaccess file:

    <Files ~ "categories|products|news|reviews|testimonials|contact|downloads|store-locator|auth">
    ForceType application/x-httpd-php
    </Files>

  4. The first line of the code above contains the names of your URL bases, which correspond to the "Category Base", "Product Base", "News Base", and "Reviews Base" fields on your Store Settings page. If you changed the values of those fields from their defaults, you will also need to change the corresponding values in the first line of your .htaccess file.
  5. Create a file with a name matching the value of your Category Base field (categories by default) in the same spot you put your .htaccess file, and put the following code in it:

    <?php
    // prefix path info with the name of this file, which should equal the URL Base for whatever purpose this file servers
    $_SERVER['PATH_INFO'] = '/'.basename(__FILE__).$_SERVER['PATH_INFO'];

    // include storefront page
    include 'store.php';
    ?>

  6. If you renamed your storefront page to something other than "store.php", change the string 'store.php' in the code to match your storefront page name.
  7. Make a copy of that file, and rename it to match the value of your Product Base field (products by default).
  8. If you have the News module installed, make another copy of the same file and rename it to match the value of your News Base field (news by default).
  9. If you have the Reviews module installed, make another copy of the same file and rename it to match the value of your Reviews Base field (reviews by default).
  10. If you have the Testimonials module installed, make another copy of the same file and rename it to match the value of your Testimonials Base field (testimonials by default).
  11. If you have the Contact module installed, make another copy of the same file and rename it to match the value of your Contact Base field (contact by default).
  12. Load the following URL in your browser (changing the domain name to your own):

    http://www.example.com/products/


    If you receive a page looking like your storefront page but with a red 404 error in the center, then the process worked. The 404 error appears because you aren't linking to a specific category. If you receive an Internal Server Error, your server may not support the "ForceType" directive. Open your .htaccess file, and change the word "ForceType" to "SetHandler", save the file, and try the test again. ForceType and SetHandler do the exact same thing.
  13. If you couldn't get the test in step 10 to work, your server doesn't have support for ForceType or SetHandler. If you contact your webhost they may be able to add support for you. If the test did work, continue.
  14. Now that you have your .htaccess file configured and working properly, you just need to tell Squirrelcart to remove the storefront page from the URLs that it generates. To do this, check the No Filename field on your Store Settings page, in the section labeled SEO URLs and click the "save changes" button.
  15. You're done! Head to your storefront page and click your product and category links to make sure they are working OK.

 

Broken Images and Links

On a default installation of Squirrelcart, the SEO URL feature will work fine. If you have customized your storefront page or product/category descriptions to include image tags or links, those images and links may break. This explains why, and how to resolve it. 

Absolute and Relative URLs

 

An absolute URL includes your domain name, as in the src attribute of the IMG tag below.

Example 1: absolute URL 

<img src="http://www.example.com/images/my_logo.gif" />

 

A relative URL is relative to the page that you are currently on in your browser.

Example 2: relative URL

<img src="images/my_logo.gif" />

 

The image tag in example 1 would work on any page that contains that code, regardless of the location of the file (even on a different website). This is because it contains the full location pointing to the image file.

The image tag in example 2 will only work when it appears on a web page that is in a folder containing a folder named images.

How this applies to Squirrelcart's SEO URL feature

If you have the code shown in example 2 above on your storefront page (store.php in this example), and are using query string URLs in Squirrelcart, loading this example category URL would result in the image my_logo.gif loading without a problem:

http://www.example.com/store.php?crn=123

 

If you enable SEO URLs, your category (and other) URLs will change to something like this:

http://www.example.com/store.php/categories/mystery-novels

 

If you load that URL in a browser, the image tag shown in example 2 that used to work will now result in a broken image. This is because your browser is looking for the image relative to the current location. It is basically looking for the image here:

http://www.example.com/store.php/categories/mystery-novels/images/my_logo.gif

How to resolve this

There are 2 ways to resolve this.

 

Option 1 - Change relative URLs to absolute URLs using Squirrelcart's root variables  (recommended)

When the code appears on a PHP page with Squirrelcart's code on it, it's best to use Squirrelcart's built in constants to insert the root URL for your store or image directory into your code. For example, this constant will be set to the  regular "http" URL of your image folder when you are on a regular page, and your secure root URL to the same folder when you are on a secure page.

Example 3: Absolute URL using Squirrelcart's SC_IMG_DIR_DYN constant

<img src="<?php print SC_IMG_DIR_DYN ?>/my_logo.gif" />

 

You can find a list of our constants at the bottom of this page.

 

Option 2 - Change relative URLs to be relative to the top level directory

When a relative URL starts with a forward slash, it tells your browser to start looking for that file in the top level directory. Changing your URLs like this will keep them working with the SEO URL feature enabled.

Example 4: relative to root of site

<img src="/images/my_logo.gif" />

 

Canonical Links

Pages may have a few different URLs that may point to the same page, for filtering results, sorting, changing page numbers, tracking affiliate links, etc...

This may cause search engines to treat those page variants as duplicate content. To prevent this, Squirrelcart automatically sets a canonical <link/> tag on these pages, pointing to the correct master URL for these variant URLs.

For example, if you are tracking add clicks to a product page via a custom parameter like adclick, you may want to send a customer to a product page like this so you can track the ad click via your web statistics software:

http://www.example.com/books/?adclick749af82734

If this page is indexed by a search engine, it looks just like the version without the adclick parameter and looks like duplicate content. For the above example, Squirrelcart will automatically add this link to prevent that from happening:

<link rel="canonical" href="http://www.example.com/books" />

Pagination

When viewing a category or when viewing search results, if more products are available than will fit on a page, that page may contain page navigation links to navigate to other pages in the data set.

Search engines may see these pages as duplicate content. To help search engines understand pagination, Squirrelcart implements one of two different features, depending on your settings:

Prev and Next Links

When there are more pages in a dataset than the number specified in the above setting, all paginated result pages automatically get a <link/> tag added to their <head/> tags, to explain the pagination, using the rel="prev" and rel="next" attributes. For example, on page 2 of a category containing 3 or more pages, these tags will be added to the <head/> tag:

<link rel="prev" href="http://www.example.com/books/page-1/" />
<link rel="next" href="http://www.example.com/books/page-3/" /> 

Linking to Products and Categories 

We've added some functions to make it easier to link to products and categories in custom PHP code. If you need to do this, we recommend using these functions, as they will use the appropriate URL format based on your settings, and will automatically be updated should you change the SEO URL Name field on your records. Just plug in your product or category record number.

Linking to a Product Page

<a href="<?php print get_product_url(854) ?>">checkout this product</a>

 

Linking to a Category Page

<a href="<?php print get_category_url(64) ?>">checkout this category</a>


 

 

 

 


© 2001-2017 Lighthouse Development. All Rights Reserved.