The Guideline for SE-Friendly URL Rewriting

Published: 04th February 2011
Views: N/A
Ask About This Article Print Republish This Article
The hurdle you must overcome when implementing the URLs shown earlier is that they don’t actually exist anywhere in your web site. Your site still contains a script — named, say, product.php — which

expects to receive parameters through the query string and generate content depending on those parameters.URL rewriting allows you to transform the URL of such an incoming request to a different URL according

to a defined set of rules. You could use URL rewriting to transform the previous non-existent URLs to product.php?product_id=123, which does exist.



The URL rewriting service is provided by the Apache web server through the mod_rewrite module. PHP does not have anything to do with it, because the PHP engine takes charge only once the .php file is executed.

The mod_rewrite module is the de-facto standard for URL rewriting in the Apache world, and is typically supported by any Apache-based hosting package.The mod_rewrite Apache module is an invaluable tool to web developers tasked with architecting


complex dynamic sites that are still search engine friendly. It allows the programmer to declare a set of rules that are applied by Apache on-the-fly to map static URLs requested by the visitor to dynamic

query strings sent to various PHP scripts. As far as a search engine spider is concerned, the URLs are static.



Installing mod_rewrite

If you’re implementing the exercises in this book using an external hosting provider, it’s very likely that mod_rewrite is already installed and enabled. In that case, you can simply skip to the next section, "Testing

mod_rewrite." Consult your web host for information regarding whether mod_rewrite is supported and enabled. If you’ve installed Apache yourself, read on. Because of its popularity, mod_rewrite is now included

with all common Apache distributions. If desired, you can verify if your Apache installation has the mod_rewrite module by looking for a file named mod_rewrite.so under the modules folder in your

Apache installation directory.




Testing mod_rewrite

Once mod_rewrite is installed and enabled, you add the rewriting rules to the Apache configuration file, httpd.conf. Apache also lets you save configuration options (including rewriting rules) on a

per-directory basis to a configuration file named .htaccess. All you have to do is create a file named .htaccess into a directory of your application, and Apache will read it automatically when accessing

that directory.As with mod_rewrite, .htaccess isn’t related to PHP in any way. The .htaccess file is strictly an Apache configuration file. You’ll see how it works in the exercise that follows.

Using .htaccess is useful in the following scenarios: You don’t have access to the global configuration file, httpd.conf You want to have customized configuration options for a particular directory of the application.

You want to be able to change the configuration options without restarting Apache. You are required to restart Apache after modifying httpd.conf, and this is problematic if you have

live applications running on the web server.All of the exercises in this book are designed to work with the .htaccess file. This is the method we generally recommend for defining rewriting rules, especially in the development stage when the rules

change frequently. This way you avoid restarting Apache every time you change a rewriting rule. It is also the only solution in a shared hosting environment,



Rewriting Keyword-Rich URLs

These URLs include keywords. However, we’ve sneaked IDs in these URLs, in a way that isn’t unpleasant to the human eye, and doesn’t distract attention from the keywords that matter, either.



Building a Link Factory

Back in the days when you worked only with dynamic URLs, it was easy to build the URLs right in the application code without much planning. You cannot do that here. If you want to use keyword-rich

URLs in your web site, just having a RewriteRule in your .htaccess file isn’t enough! You also need to ensure that all the links in your web site use these keyword-rich versions consistently throughout the

web site. Obviously, including the URLs manually in the web site is not an option — it’s a dynamic site after all, and the link management task would quickly become impossible to handle when you have a

large number of products in your catalog! Fortunately, there’s a very straightforward solution to this problem, which as soon as it’s put in place,takes away any additional link management effort. The solution we’re proposing is to use a function to

generate the new URLs based on data already existing in your database, such as product or category names.









My name is daksh and i help online business to improve their link popularity and especially for social bookmarking service, article submission service and directory submission service.

This article is free for republishing
Source: http://jamesdaksh.articlealley.com/the-guideline-for-sefriendly-url-rewriting-2006597.html


Report this article Ask About This Article Print Republish This Article


Loading...
More to Explore
 


Ask a Professional Online Now
27 Experts are Online. Ask a Question, Get an Answer ASAP.
Type your question here...
Optional:
Select...