HomeWeb WorldChecklist and Troubleshooting URL Rewriting

Checklist and Troubleshooting URL Rewriting

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.

 

RELATED ARTICLES

Most Popular