Advanced URL Rewriting with Miva Merchant
March 26, 2008 by Susan Petracco
URL Rewriting is a way of changing the URLs within a website to a more logical and/or more search engine-friendly format. The default URLs within a Miva Merchant site are long and full of querystring variables, and can easily be rewritten to cleaner formats, as described below. To find out if this is available for your website, check with your web host.
History
URL Rewriting first became popular among Miva Merchant sites when Copernicus released their Search Friendly Links module, long before the advent of Miva Merchant 5.0. At the time, Google favored URL structures that had, at most, a single name-value pair in the querystring. To understand this, one must look at the structure of a URL. A URL begins with either http:// or https://, followed by the domain name (such as www.google.com). After that comes another slash, zero or more directories separated by slashes, and a filename. For example:http://www.site.com/mm5/merchant.mvc
In this example, www.site.com is the domain name, mm5 is a directory, and merchant.mvc is the name of the file within the mm5 directory that is being called. A querystring is appended to the URL by adding a question mark, and then one or more name-value pairs separated by ampersands. This can be seen throughout Miva Merchant, such as the URLs that define a product page:
http://www.site.com/mm5/merchant.mvc?Screen=PROD&Product_Code=ABC123&Category_Code=flowers
In the above example, the querystring contains three name-value pairs: Screen=PROD, Product_Code=ABC123, and Category_Code=flowers. At the time that the Search Friendly Links module was released, since Google was devaluing links with more than one name-value pair, this type of URL clearly did a disservice to Miva Merchant site owners. Search Friendly Links changed the above URL to a directory structure:
http://www.site.com/page/PROD/ABC123/flowers/
Mod_rewrite
The mechanism that allows this to work is built into Apache, the webserver commonly used on *nix servers, and is called mod_rewrite. To turn on mod_rewrite for your site, you need to edit (or add) the .htaccess file in your root directory. Note that on *nix servers, files that begin with a period ("dot files") are hidden by default, so you may need to set your FTP client to show hidden files or dot files in order to see the .htaccess file in the list. Within the .htaccess file, add this command above any rewrite rules:RewriteEngine On
This command turns on the rewriting engine. Specific rewrite rules can be added based on the format chosen below.
"Supershort" or "Jedi-style" Links
Although Search Friendly Links is no longer needed with Miva Merchant 5.0 and above, mod_rewrite can still be used to generate shorter URLs that offer an advantage among the search engines, and offer the customer a more logical set of URLs for the website. One common URL format is to add a "c-" to designate category page URLs, and a "p-" to distinguish product page URLs. Using our example above, these URLs would become:http://www.site.com/c-flowers.html
http://www.site.com/p-ABC123.html
The URLs within the pages inside of Miva Merchant 5 can be changed to this format in the following manner:
http://www.site.com/c-&mvt:category:code.html
http://www.site.com/p-&mvt:product:code.html
And to allow these URLs to work, the following Rewrite Rules should be added to the .htaccess file below the "RewriteEngine On" line:
RewriteRule ^c-([^.]+).*$ /mm5/merchant.mvc?Screen=CTGY&Category_Code=$1&%{QUERY_STRING} [T=application/x-httpd-mv,L]
RewriteRule ^p-([^.]+).*$ /mm5/merchant.mvc?Screen=PROD&Product_Code=$1&%{QUERY_STRING} [T=application/x-httpd-mv,L]
"Store" directory - Miva Merchant within a larger site
Sites that include a Miva Merchant store within a larger framework of pages or applications might want all shopping cart pages to appear in the /store/ directory, for example. Using this in combination with the "supershort" link format above produces:http://www.site.com/store/c-flowers.html
http://www.site.com/store/p-ABC123.html
The SMT code looks like this:
http://www.site.com/store/c-&mvt:category:code.html
http://www.site.com/store/p-&mvt:product:code.html
And the rewrite rules might look something like this:
RewriteCond %{QUERY_STRING} Screen=CTGY [NC]
RewriteCond %{QUERY_STRING} Category_Code=(.*)& [NC]
RewriteRule ^(.*) http://www.site.com/store/%1.html? [R=301,L]
RewriteCond %{QUERY_STRING} Screen=CTGY [NC]
RewriteCond %{QUERY_STRING} Category_Code=(.*)$ [NC]
RewriteRule ^(.*) http://www.site.com/store/%1.html? [R=301,L]
RewriteCond %{QUERY_STRING} Screen=PROD [NC]
RewriteCond %{QUERY_STRING} Product_Code=(.*)& [NC]
RewriteRule ^(.*) http://www.site.com/store/%1.html? [R=301,L]
RewriteCond %{QUERY_STRING} Screen=PROD [NC]
RewriteCond %{QUERY_STRING} Product_Code=(.*)$ [NC]
RewriteRule ^(.*) http://www.site.com/store/%1.html? [R=301,L]
Smart Links - The Shortest Possible Links
By adding the Smart Links for SEO™ module, it is also possible to create even shorter links. This module takes the string after the domain name, and looks within the Miva Merchant database to determine whether the string represents a category code, a product code, or a page code. (Note that when using this module, a store should NOT have product codes, category codes, and screen codes that overlap each other; they should all be unique.) This module allows a store to display these type of URLs:http://www.site.com/flowers.html
http://www.site.com/ABC123.html
http://www.site.com/aboutus.html
In the first URL, "flowers" refers to a category code. In the second one, "ABC123" refers to a product, and in the final URL, "aboutus" is the code for a custom page. The rewrite rule for this format is simple, as it redirects the user to a single URL controlled by the Smart Links for SEO module. The rule looks like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)\.html$ /mm5/merchant.mvc?Screen=NBSEOLINK&thecode=$1 [L]

Enter your email address below to receive new posts in your email inbox.



Review Of DoublePlus.com
October 4th, 2008
[...] on Search Engine Optimization, such as Building Authority And Inbound Links With Squidoo and URL Rewriting. It also uses the top commentators widget, so I’ll have to add this one to my [...]
Aditya
July 9th, 2009
I’ll like to add it to my blog too.
Richard @ Internet Marketing Brisbane
September 3rd, 2009
Excellent tips, well written with details of how to actually change the code. If your looking to rank well and beat the competition then SEO friendly URL’s for your store are a must.