Search

Mod_rewrite: A Users Guide

Mod_rewrite: A Users Guide

Setting your AOM site up for mod_rewrite can be a crucial step towards making your site both more user-friendly, and search engine-friendly. But to many people, especially those without much experience, it can seem like a daunting task. We’re going to break the steps down, and make this important area look like the easy setup that it actually is.

A few notes at the beginning: the mod_rewrite feature is only available with the 30-day trial and the full (paid) versions of Associate-O-Matic. It is not available with the Lite version. And the process I’m going to outline here only works on AOM when set up on a Linux (as opposed to Windows) server. Bear in mind this has nothing to do with the operating system your computer uses, rather the system your webhost has in place to run your site. If you’re not sure, check with your webhost.

If you’re wondering what mod_rewrite can do for you, it’s simple. Let’s look at an URL with mod_rewrite off, then the same URL with mod_rewrite on:

  • http://www.mysite.com/shop.php?c=7&n=404276&i=B001C08RHA
  • http://www.mysite.com/7-404276-B001C08RHA-Iron_Man_Single_Disc_Edition.html

Which one do you like better? Which one will customers and search engine spiders like better? The second link is certainly easier to read, you have a good idea what it’s about, and it looks more ‘professional’ than the link above it. The second link also seems like it would have a better chance of coming up in a Google or Yahoo! search if someone was looking for ‘Iron Man single disc edition’. This could be your site.

Okay, the first thing you’ll need is a special file called .htaccess – spelled exactly like that, with the period in front. This file goes in the same directory as your admin.php, aom.php and shop.php files. If you already have one in place, great. If not, you can create one. Some webhosts won’t let you create or upload a file without a ‘blahblah.bla’ format. If so, create the file as ‘htaccess.txt’. Then you can rename it simply as .htaccess later on.

Once you have the file in place, you need to make some decisions about what to put into it. And for that, we need to look in your AOM control panel.

Here we see the main options under the SEO tab of your control panel (I’ve turned off the descriptions to fit them all into one compact image). The first five are the most important. seo1The first option (Mod Rewrite) simply turns the feature on or off. When we have everything set up, don’t forget to switch this to ON.

The next option is to use hyphens or underscores as the separator in the URLs that will be created. The option you select will be used between the category ID, the node (if any) and the ASIN. The title or name of the item will be in the reverse (underscore, if you select hyphen; or hyphen, if you select underscore). Like this:

  • Hyphen: 7-404276-B001C08RHA-Iron_Man_Single_Disc_Edition
  • Underscore: 7_404276_B001C08RHA_Iron-Man-Single-Disc-Edition

Because of the formatting required for the mod_rewrite function, you can’t have all hyphens or all underscores.

The next option is URL Home File. Whatever you pick here (the default is home) will be the internal link back to your home page, from the breadcrumb trail, the Home tab, etc. The homepage of your site will be something like www.mysite.com/home when you click on one of these internal links. If you don’t want to use anything for this link, a good option to use is ../ (yes, that’s two periods and a slash; that’s computer-talk for the main page of this site, whatever it is).

After that is URL Ends With. Your options here are either .html or nothing. Ending a URL with .html is generally seen as ‘friendlier’ in a search-engine sense than almost any other suffix. Some people may prefer not to have any sort of ending.

The last important choice is URL With Name. if You choose this option, the item or category name (where applicable) will be appended to the URL. This is another all-or-nothing selection:

  • 7-404276-B001C08RHA-Iron_Man_Single_Disc_Edition
  • 7-404276-B001C08RHA

The difference is obvious, as are the benefits of having the name included in your site indexing. Our final selection, URL Name Length, is not quite so important for mod_rewrite, but allows you to select the maximum character length for your URLs. If they’re too long, search engines may not like them; too short and you lose the benefit of having the name appended (if that option is chosen). The recommended length is the default setting of 200 characters.

Once you have all these options selected in your control panel (Separator, Home File, Ends With & Name; Length is not required for the next step), you need to go to this page of the Associate-O-Matic online documentation and select a Ruleset that matches your options.

For example, if you go with all the default settings:

  1. Separator: Hyphen
  2. Home File: Home
  3. Ends With: .html
  4. Name: yes

Then you would use Ruleset #1. Copy these rules and paste them into your .htaccess file. If you have a different set of options, find which ruleset matches your choices and copy & paste the corresponding ruleset into your .htaccess file.

**Important Note Number 1** If you change your Home File Name to something other than home, you must also change the second line of the ruleset you choose. If you go with the example I used (../), then change the second line to:

  • RewriteRule ^../ shop.php

**Important Note Number 2** If you have changed your shop.php file name (usually people change it to index.php), you must go through the ruleset you’ve chosen and change every instance of shop.php to the name you are now using. Easy to do if you paste the rules into a text editor like Notepad and use ‘find and replace’ (don’t use Word; it adds hidden codes and things and makes it all a mess).

The important thing about the last three or four paragraphs is that the options you set in your control panel must match the rulesets you put in your .htaccess file. Once you’ve got all that, make sure you turn the Mod_rewrite feature on in your control panel and save. Save your .htaccess file.

Now, if you go to your store and refresh it, your URLs should l
ook cleaner and leaner, easier to read and easier to index. If you start getting strange errors, here are a few things to check:

  1. As mentioned at the beginning, make sure your site is running on Linux. Windows servers don’t work properly with .htaccess files.
  2. Go through your control panel SEO settings and make sure they match the ruleset you’ve pasted in your .htaccess file.
  3. Make sure the file really is .htaccess and not htaccess.txt or .htacess, etc.
  4. If you have custom URLs hardcoded into your site (like a custom homepage html section), you may need to change the URLs to match the new format. Usually this may only happen with things like category links in menus.
  5. If you have a pre-existing .htaccess file, there may be a conflict with any code that was added previously. If you have a command like DirectoryIndex shop.php in your file, make sure it goes above the Ruleset.

Some webhosts (GoDaddy is #1 for this) have their own strange rules for .htaccess files. The AOM forum has some suggestions for help in this area. You can also contact your webhost for assistance, or open an AOM support ticket.

Final Note: It’s recommended you set up mod_rewrite as soon as possible in the lifetime of your store. Once you do set it up, think long and hard before changing the options (and rulesets). Doing so will break any pre-existing links that may have been indexed for your site, and force you to start over from scratch in terms of search engine indexing, ranking, etc. So hopefully it will be a case of ‘set it and forget it’.

Latest posts

14 thoughts on “Mod_rewrite: A Users Guide

  1. Xaza

    I found the problem of Error 404 when I use Multiple browse nodes.
    Multiple browse nodes now supported for Categories (eg 1111,3333).

    URI Error page to link Product Details.

    I think I need more Mod_rewrite but no experience in working with Mod_rewrite Please help me if you can.

  2. mcarp555

    You should probably open a support ticket on the AOM site, including details like the URL, a copy of your cfg.saved.php file, etc.

  3. NewMoney

    Wasn’t there some way of getting rid of the “shop.php?” in the middle of the URL after the rewrite?

  4. Mike

    Check the ‘Five New User Questions’ in the grey box at the top of the page.

  5. Uploaded files Cant move on

    Hi, im unsure what to do next, I uploaded the files after downloading from the site, the trial version, changed the name of one of the files as directed, I cant go to admin to set up a new shop, or even the cpanel, im stuck, im sure im missing something simple can some one please assist

  6. Fantastic instructions…works a charm!

  7. For your rule set #1, I was able to use the instructions posted by littletoons at http://www.associate-o-matic.com/forum/viewtopic.php?f=8&t=4124 to make this work.

    Just using “../” in the admin interface and “RewriteRule ^../ shop.php” in the “.htaccess file” resulted in the server not being able to find the home page. I believe this is because of the way the directory for my site is positioned on my server.

  8. How about using a custom rewrite mode to do away with the Amazon part of the url, so instead of having:

    http://www.mysite.com/7-404276-B001C08RHA-Iron_Man_Single_Disc_Edition.html

    how about:

    http://www.mysite.com/Iron_Man_Single_Disc_Edition.html

    That would be way better for the seo. How could I implement that and would there be any negative consequences?

  9. mcarp555

    The various parameters (Cat ID, Node and ASIN) are required in the URL, otherwise the system can’t keep track. You’re welcome to experiment with the rules on your own to see if there is a workaround, but so far we haven’t seen one.

  10. seems my site does not support php files,
    I have downloaded as described, ftp files to web site. everything says OK,but when I try to open the admin.php file, I get a new web page open with the scripting of the file, I haven’t even got close to a control panel
    Account is Tripod, is there a way to get the site to acknowledge the php files? or should I give up and go to a recommended site,
    anyone recommend a good one?

  11. mcarp555

    PHP is a requirement for AOM. Contact your webhost to ask if PHP is available. If not, you will be unable to use the software with that host.

  12. […] to set up if you take the time to read the instructions carefully. Plus there’s a detailed Users Guide on this site to help you get going on […]

Leave a Comment

Time limit is exhausted. Please reload CAPTCHA.