Ecommerce Templates > Search engine friendly > Search engine friendly URLs - PHP Version
It is possible to make the URL structure of the ECT generated URLs even more search engine friendly by removing any files extensions or query parameters by using URL Rewriting - (Your server must support this), leaving you with the cleanest URL possible, www.yourstoreurl.com/your-product-name. This should also help in your offline marketing efforts, making it much easier to show and spell out the URL of particular products and categories. This feature requires a minimum version of ECT of 6.4.
These are the steps required if you are using the PHP version of Ecommerce Templates
Open your products.php and categories.php pages and before the closing </head> tag add the following
<base href="http://www.yourstoreurl.com/" />
If you are using WordPress that can go in the file header.php somewhere before the closing </head> tag.
If you have your store in a different folder and not in the web root that would be something like
<base href="http://www.yourstoreurl.com/store/" />
If your site has an SSL certificate installed that would need to be
<base href="http<?php if(@$_SERVER['HTTPS']=='on') print 's'?>://www.yourstoreurl.com/" />
In vsadmin/includes.php the following parameters are available...
$seodetailurls=TRUE;
$seocategoryurls=TRUE;
$detlinkspacechar="-";
$seocaturlpattern="/category/%s";
$seoprodurlpattern="/products/%s";
$seomanufacturerpattern="/manufacturer/%s";
$seourlsthrow301=TRUE;
The parameters explained
By setting this parameter the cart will produce Product Detail Page URLs in the new SEO format...
$seodetailurls=TRUE;
By setting this parameter the cart will produce Category and Product Page URL's in the new SEO format...
$seocategoryurls=TRUE;
This parameter is optional but if used will replace space characters in your product names with the character specified.
$detlinkspacechar="-";
These parameters are optional but can be used to override the default category and product page formats.
$seocaturlpattern="/category/%s";
$seoprodurlpattern="/products/%s";
$seomanufacturerpattern="/manufacturer/%s";
This parameter is optional and shouldn't be used until you have your SEO URL system fully functional. Adding this parameter will cause an HTTP 301 Moved Permanently error to be generated (to inform Search Engines that your page has moved to a new location) and will cause the page to automatically forward to that new location.
$seourlsthrow301=TRUE;
The last step is to create a .htaccess file. It may be you already have a .htaccess file in your store root but if you don’t you can make your own by opening up your preferred text editor like Notepad and pasting in the following code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^category/([^/]*)/?$ /categories.php?cat=$1 [QSA,nc,L,B]
RewriteRule ^products/([^/]*)/?$ /products.php?cat=$1 [QSA,nc,L,B]
RewriteRule ^manufacturer/?$ /categories.php?man=all [QSA,nc,L,B]
RewriteRule ^manufacturer/([^/]*)/?$ /products.php?man=$1 [QSA,nc,L,B]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) proddetail.php?prod=$1 [QSA,nc,L,B]
</IfModule>
Then go to Save As, choose “Save As Type > All Files” and enter .htaccess – making sure it’s not saved at a .txt file or with another file extension. Upload that file to your store root (where you have the cart.php, products.php thanks.php etc files)
If you are already using a .htacess file, add the code above and save and upload.
WordPress users
SEO URLs are automatically handled for the shopping cart by the ECT Widgets plugin.
From Version 6.9.2 Extensionless URL's or URL's with non-standard extenions can be created for all cart pages by specifying the parameter "extension" in your includes.php file. For extensionless URL's you can set the parameter to an empty string as follows...
$extension="";
You may also want to use a trailing slash for cart pages, for instance...
$extension="/";
This would make the cart page URL
yoursite.com/cart/
For this to work you do need to have access to a URL rewriting method as the rewritten URL needs to be mapped back to the page name with the .php extension, but it will mean that internally generated links will use the extension you specify.
For example, for the cart page an URL like this http://www.ectdemostore.com/uk_demo/cart/ would need the following adding to .htaccess
RewriteRule ^cart/$ cart.php [NC,L]
Remember to add the following in the HEAD section somewhere before your css lines on each of the extensionless URL pages.
<base href="http<?php if(@$_SERVER['HTTPS']=='on') print 's'?>://www.yourstoreurl.com/" />
It's crucial that once you have the extension-less URLs set up that you fully test your store. This not only means flicking through the pages and links on your site but also looking under the hood and making sure the correct server headers are returned so search engines can find, crawl and index the new URLs.
The first thing you should do is check the HTTP status returned by the server. There are several sites that allow you to type in the URL of your pages and check the server response, for example
You would be looking at the page returning a 200 HTTP response. If you get a 404 response it would indicate a problem as your page wasn't found. In this instance you would need to go over the instructions again and if you can't find where the problem lies, please post on our support forum.
For ongoing monitoring we strongly recommend seting up a Webmaster Tools account if you don't already have one. As your site is crawled any server errors will be reported along with the referring link and date of discovery. It may take several days or weeks for new pages to be found and reported but it does allow you to keep on top of any errors over time.
If you are using the multiple language feature the content of the .htaccess file will be slightly different.
For example if you have your Spanish language site set up in a directory called /es/ your .htaccess file would look like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^es/category/([^/.]*)/?$ /es/categories.php?cat=$1 [QSA,nc,L]
RewriteRule ^es/products/([^/.]*)/?$ /es/products.php?cat=$1 [QSA,nc,L]
RewriteRule ^es/manufacturer/?$ /es/categories.php?man=all [QSA,nc,L]
RewriteRule ^es/manufacturer/([^/.]*)/?$ /es/products.php?man=$1 [QSA,nc,L]
RewriteCond $1 !\.(png|gif|jpg|ico|css|js|php)$ [NC]
RewriteRule ^es/([^/]+)$ /es/proddetail.php?prod=$1 [QSA,nc,L]
RewriteRule ^category/([^/.]*)/?$ /categories.php?cat=$1 [QSA,nc,L]
RewriteRule ^products/([^/.]*)/?$ /products.php?cat=$1 [QSA,nc,L]
RewriteRule ^manufacturer/?$ /categories.php?man=all [QSA,nc,L]
RewriteRule ^manufacturer/([^/.]*)/?$ /products.php?man=$1 [QSA,nc,L]
RewriteCond $1 !\.(png|gif|jpg|ico|css|js|php)$ [NC]
RewriteRule ^([^/]+)$ proddetail.php?prod=$1 [QSA,nc,L]
</IfModule>
Also make sure you have the $orstoreurl set in the es/vsadmin/includes.php file.
If the css doesn't render on your new search engine friendly pages, make sure that the "base href" line comes somewhere before any css line or the "incectstyle.php" include line, eg
<base href="http://www.yourstoreurl.com/" />
<?php include "vsadmin/inc/incectstyle.php"; ?>
<link rel="stylesheet" type="text/css" href="/style.css" />
If you are seeing some 404 errors on particular products or categories, check that the product or category name doesn't include non-permitted characters such as a dash or period.
If you have a product or category name with the decimal point / period / dot you can replace this line in the .htaccess file
RewriteRule ^([^/.]+)$ proddetail.php?prod=$1 [QSA,nc,L,B]
with
RewriteCond $1 !\.(png|gif|jpg|ico|css|js|php)$ [NC]
RewriteRule ^([^/]+)$ proddetail.php?prod=$1 [QSA,nc,L,B]