» Birthday Bundle - Over $400 worth of Envato files for just $20
  Posts tagged 'mod_rewrite'

Making Friendly URLs

Posted on August 29, 2008, Filled under PHP,  Bookmark it

The aim of this tutorial is to show you how to make SEO Friendly URLs. First of all you must check if your Apache Server has the mod_rewrite module enabled.

Too many parameters in an URL can create problems in crawling for a Search Engine. A friendly optimised URL would always be a better alternative if this option is available to you. These URLs are better indexed by Search Engines and people are more likely to click on static links which contain a description of what the link is about.

The rewriting rules should be written in the .htaccess file that must be created and uploaded in the main root of your site.

Here’s an example of a dynamic URL:

http://www.yourdomain.com/?c=5&p=20

A better (SEO) alternative of this URL would be:

http://www.yourdomain.com/articles/5/20-seo-techniques.html

You can obviously notice what this URL is about.

The server sends a request to the .htaccess file passing the category id and the post id.

The .htaccess file will look like this:

# Enable mod_rewrite
RewriteEngine On 

# Sets the base URL for per-directory rewrites
RewriteBase /

RewriteRule ^articles/([0-9]+)/([0-9]+)-seo-techniques.html$ /?c=$1&p=$2

We use regular expressions to tell the script that only numbers values should be parsed. The static url is automatically converted to the dynamic one.

Here are more examples of rewrite rules:

RewriteRule ^terms-and-conditions.html$ /index.php?module=terms

# example: http://www.mydomain.com/category/10/post/35/php-functions.html
RewriteRule ^category/([0-9]+)/post/([0-9]+)/(.*).html$ /?c_id=$1&p_id=$2

By using this rewrite techniques your URLs are better indexed by search engines and are more likely to have a higher rank.

Enabling mod_rewrite module in Apache HTTP Server

Posted on August 27, 2008, Filled under PHP,  Bookmark it

Hello,

In this short tutorial we will learn how to enable the mod_rewrite module in Apache Server.

Step 1
Locate the folder where apache is installed (in localhost is usually in: C:Program FilesApache Software FoundationApache2.2). Find the folder “conf”. You will find in it the file: httpd.conf.

Step 2
Find the line #LoadModule rewrite_module modules/mod_rewrite.so. Uncomment it so it will look like this:

LoadModule rewrite_module modules/mod_rewrite.so

Look for #AddModule mod_rewrite.c and uncomment it as well.

AddModule mod_rewrite.c

In the same file search for:

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

and replace it with:

<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>

You may have many other attributes between the ‘Directory’ tags. Make sure that AllowOverride is set to ‘All’.

Save the new httpd.conf and restart Apache.

Good luck!