There are no comments yet...Kick things off by filling out the form below.
Whether you are updating your Apache-based site to a new directory structure or want to make your URL addresses more search-friendly, the mod_rewrite module can apply automated updates to your URLs according to set rules. The most common use for the module is to have logically named file names and directories which will improve user navigation as well as search optimization on your site.
Many web publishing packages for Apache feature dynamic URLs which call a category and content based upon a proprietary directory structure. Further, showing the full directory URL can potential create security threats by providing visitors with full access to your underlying server directory structure. Therefore, for usability, security and marketing purposes, it’s important to rewrite your Apache URLs to a more friendly structure.
Most Apache serves have mod_rewrite installed but the package isn’t enabled by default. To enable the module you just have to remove commenting (#) from the following lines in your httpd.conf configuration file:
AddModule mod_rewrite.c
LoadModule rewrite_module modules/mod_rewrite.so
Once you have enabled the module, you can safely reboot your server to ensure the new settings are recognized. The easiest way to implement redirects is by editing your .htaccess file, which is in the root of your public_html (or public) folder.
There are several basic redirects you can implement with mod_rewrite to improve navigation on your site. To start make sure you add “Rewrite Engine On” to the file.
Basic redirects to new locations
This is used when you want to redirect a previous URL file structure to a new location. In order to implement the redirect, you just have to add a line of code to the .htaccess file accordingly by utilizing special characters to denote the start and end of the URL string:
RewriteRule ^previous\.html$ updated.html [R]
Dynamic URL Redirects
Rather than manually updating each URL you can use a dynamic expression to redirect URLs according to a set of rules. For example if you currently have your content organized according to a file structure /article/item99 where 99 is the article ID, you can rewrite to a simplified structure:
RewriteRule ^article/([0-9][0-9])/$ /articles.php?articleID=$1
There are no comments yet...Kick things off by filling out the form below.