Home Web World Checklist and Troubleshooting URL Rewriting

Checklist and Troubleshooting URL Rewriting

0
435

Checklist to Implement URL Rewriting

  1. CHECK THAT IT’S SUPPORTED
    Not all Web servers support URL rewriting. If you put up your .htaccess file on one that doesn’t, it will be ignored or will throw up a “500 Internal Server Error.”
  2. PLAN YOUR APPROACH
    First thing first, you have to figure out the mapping structure, so that the correct information is getting found everytime user browses your site.
  3. CREATE YOUR REWRITE RULES
    All the rules have to be defined in an .htaccess file. To test whether the URL rewriting is working, you can use it in “test” subdirectory and use the [R] flag, so that you can see where things go:

    RewriteEngine On
    RewriteRule ^.+/p/([0-9]+)   product.php?id=$1     [NC,L,R]
    RewriteRule ^.+/c/([0-9]+)   category.php?id=$1    [NC,L,R]
    

    Now, if you visit www.myweb.com/test/product/p/123, you should be sent to www.myweb.com/test/product.php?id=123. Once you’re satisfied, move the .htaccess file to your document root and remove the [R] flag.

  4. CHECK YOUR PAGES
    After making changes in the .htaccess file, the next step is to test that your URLs are bringing in all the correct images, CSS, and JavaScript files. For example, the Web browser now believes that your Web page is named 123 in a directory named product/p/. If the HTML refers to a file named images/logo.jpg, then the Web browser would request the image from www.myweb.com/product/p/images/logo.jpg and would come up with a “File not found.”
    In that case, you would either need to rewrite the image locations or make the references absolute.
  5. CHANGE YOUR URLS
    Find all the references of old URLs, and replace them with the new URLs, using a function such as GenerateUrl to consistently create the new URLs. This is the only step that might require looking deep into the underlying code of your website.
  6. AUTOMATICALLY REDIRECT YOUR OLD URLS
    Now that the URL rewriting is in place, you probably want Google to forget about your old URLs and start using the new ones. That is when a search result brings up product.php?id=20, you’d want the user to be visibly redirected to product/p/123, which would then be internally redirected back to product.php?id=20.This is the reverse of what your URL rewriting already does. In fact, you could add another rule to .htaccess to achieve this, but if you get the rules in the wrong order, then the browser would go into a redirect loop.

    Another approach is to do the first redirect in PHP, using something like the CheckUrl function above. This has the added advantage that if you rename the product, the old URL will immediately become invalid and redirect to the newest one.

  7. UPDATE AND RESUBMIT YOUR SITEMAP
    Make sure to carry through your new URLs to your sitemap, your product feeds and everywhere else they appear.