vicker313 tech blog

October 7, 2009

Create Search Engine Friendly URL at Apache

Filed under: Apache — Tags: , — vicker313 @ 8:35 am

URL Query String is the string append to the web page URL. For example http://www.google.com/search?q=url+query+string, the string after the question mark (?) is the query string.

Most of the surfers will not care about the URL, which they consider them as alien language. However it would be nice if the URL can be translated into something more friendly to surfers, and most important to the search engine.

If your web server is Apache, you might follow the steps below to rewrite the URL (assume the folder of your website is webdir inside your document root):

  1. Enable the rewrite module in Apache. To do this, you need to edit the configuration file conf\httpd.conf.
  2. Find the following line and uncomment it.
    LoadModule rewrite_module modules/mod_rewrite.so
  3. In some scenario, you need to set the AllowOverride parameter to All as well.
    <Directory "document roots">
    ...
    AllowOverride All
    ...
    </Directory>
  4. Then restart the server.
  5. Create a file called .htaccess at webdir.
  6. Add the following coding or sample to .htaccess.
    RewriteEngine On
    RewriteBase /webdir/

    RewriteRule index.html$ index.php [NC]
    RewriteRule index/([^/]+)$ index.php?a=$1 [NC]
    RewriteRule index/([^/]+)/([^/]+)$ index.php?a=$1&b=$2 [NC]

Now when you type:

  • index.html, it will translate to index.php
  • index/category, it will translate to index.php?a=category
  • index/cateogory/linux, it will translate to index.php?a=category&b=linux
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: