Mod_Rewrite URL's for Search EnginesMod_Rewrite is a module in Apache webservers that allows you to manipulate URL's. Mod_Rewrite can be quite powerful, and is known as a "voodoo" tool and "the swiss army knife of url manipulation." In this tutorial, Im going to cover using Mod_Rewrite and regex to increase hits to your site from search engines (like Google) by making them search engine friendly.
Should I? or Shouldn't I?Search engines will not crawl deep into query strings. Im saying deep because it is true that the spider will crawl a query string a bit, but this is overall a good decision in other areas as well, take a look:
So if you're reading this tutorial you've found that search engines do not like query strings, and deal much better with text based directories. So if we make your urls look like this:
Then the search engines will be more than happy to make that information available in searches.
Getting StartedFirst, lets assume that the url's to your site currently look a bit like this:
our goal and final product, is to make that same file accessible by a prettier and friendlier url like this:
Ok, to eliminate problems that may occur when you begin the re-writing process, lets make sure that everything is set up right, so we can know that it have to be the code producing errors, not anything else if something goes wrong.
The mod_rewrite module must be loaded.
*Note: If you're running your own webserver, you can check by navigating to the httpd.conf file and opening it. On line 182 (Apache 1.3x), make sure it reads:
and that its not commented out (does not have # in front of it). If it does, remove the #. Now go to line 226. It should read:
If it has a # in front, remove it. Now it will be loaded when you start Apache. You can restart apache to ensure the changes go into effect, assuming that you made any.
If you're not running on your own webserver (most likely), then you will likely not have to bother with any of that stuff, because it is probably already setup for you by the server administrator. If it still wont work and you feel your code is correct, you can try inserting this:
as the first line of you .htaccess file.
The magic happens so to speak in your .htaccess file. You can make the changes for all the rewrite rules in the .htaccess of your root folder, or to the folder which you want to apply the changes, it doesn't matter either way.
No Comments for this page.