Seo-Friendly Links with mod_rewrite



mod rewrite seo friendly links

Apache’s mod_rewrite module solves several typical Search Engine Optimization (SEO) problems. It is a module which provides a powerful way to do sophisticated url manipulations. Not only can mod rewrite be used to avoid duplicate content, redirect moved urls or non existing inbound links, and create search engine friendly urls. It can also be used for to gain higher PageRank and search engines rankings, get your web site indexed by the search engines, and receiving more visitors. Here are some the most popular url manipulations.

Avoid duplicate content

RewriteEngine On
# Redirect non-www to www.
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# Redirect direct requests for "anything/index.html" to "anything/"
RewriteRule ^(([^/]+/)*)index\.html http://www.example.com/$1 [R=301,L]

Redirect relocated URLs

RewriteEngine On
# Redirect relocated old urls to the new urls
RewriteRule ^oldpage\.html$ http://www.example.com/newpage.html [R=301,L]
RewriteRule ^directory/oldpage\.html$ http://www.example.com/directory/newpage.html [R=301,L]
# Redirect relocated directories to the new directories
RewriteRule ^olddir/(.*) http://www.example.com/newdir/$1 [R=301,L]

Redirect non-existing incoming links

# Get the requested URI, query string and hostname.
RewriteCond %{REQUEST_URI} ^(/[^?]*)([?].*)?$
RewriteRule . - [E=myUri:%1,E=myQuery:%2]

# Replace hmtl, htlm, and thml file extensions with html extension.
RewriteCond %{ENV:myUri} ^(.*)[.,](hmtl|htlm|thml)$ [NC]
RewriteRule . - [E=myRedirect:yes,E=myUri:%1.html]

# Replace comma(s) or multiple filetype delimiter periods in the url
# with a single period.
RewriteCond %{ENV:myUri} ^(.*)([,.]{2,}|,)((s?html?|php[1-9]?|aspx?|pdf|xls).*)$ [NC]
RewriteRule . - [E=myRedirect:yes,E=myUri:%1.%3]

# Remove invalid trailing characters
RewriteCond %{ENV:myUri} ^([/0-9a-z._\-]*)[^/0-9a-z._\-] [NC]
RewriteRule . - [E=myRedirect:yes,E=myUri:%1]

# Remove trailing punctutation
RewriteCond %{ENV:myUri} ^(.*)[._\-]+$
RewriteRule . - [E=myRedirect:yes,E=myUri:%1]

# Do the external 301 redirect only if needed and the resource exists
# at the corrected URI.
RewriteCond %{ENV:myRedirect} ^yes$ [NC]
RewriteCond %{DOCUMENT_ROOT}%{ENV:myUri} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{ENV:myUri} -d
RewriteRule . http://www.example.com%{ENV:myUri}%{ENV:myQuery} [R=301,L]

SEO-friendly URLs

For example, your urls look like this:

http://www.example.com/widgets.php?cat=blue&page=1

Obviously, you want to transform it into something that look like this:

http://www.example.com/widgets/blue/page1.php

RewriteEngine On
RewriteRule ^widgets/(.*)/page(.*)\.php /widgets.php?cat=$1&page=$2 [L]


Optimizing Joomla Websites

web hosting

Joomla is one of the most popular content management systems available on the internet. It is a vast system with a large amount of information such as, content, images, audio and video clips. As a result, it is important to optimize websites created in...

Sep 22nd, 2010 Read more

What is the Google Sandbox?

web hosting

The Google Sandbox (also known as aging delay) is the theory that new website rankings are temporarily reduced placing them into what is known as the sandbox. Release of these websites out of the sandbox can take days, weeks, or even months; placing various...

Aug 3rd, 2010 Read more