Currently set to No Index

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

[sourcecode language=”bash”]
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]
[/sourcecode]

RELATED:   How Web Hosting Aids in SEO

Redirect relocated URLs

[sourcecode language=”bash”]
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]
[/sourcecode]

Redirect non-existing incoming links

[sourcecode language=”bash”]
# 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]

RELATED:   SEO Keywords: Keyword Density vs. Keyword Placement

# 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]
[/sourcecode]

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

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

How-to Start a Blog – Review of the Best 10 Blogging Platforms
How-to Start a Blog – Review of the Best 10 Blogging Platforms

If you want to start a blog as fast as possible, then you need to consider choosing a blogging platform. Thankfully, there are some excellent free and paid blogging platforms...

How Referral Marketing Can Benefit Web Hosts
How Referral Marketing Can Benefit Web Hosts

Even if the niche of web hosts are fully loaded with a lot of companies they are still one of the easiest to promote because you could write your own...

Broken Links: How to Find, Fix, and Benefit from Broken Links
Broken Links: How to Find, Fix, and Benefit from Broken Links

Links are what holds the web together. Essentially, the web is named as such because of the ability for pages and sites to link to other sources and relevant information....

Brand Value & the Most Powerful Brands (with Infographic)
Brand Value & the Most Powerful Brands (with Infographic)

Brand value – everyone wants it, however, only few are able to achieve it. The subject of “brand value” holds a significant position amongst marketers, executives, and entrepreneurs. Let’s discuss...

Reasons why your business should shift to Cloud hosting
Reasons why your business should shift to Cloud hosting

Cloud hosting has been on the rise since its inception. The improvement to your website performance and business efficiency that comes with Cloud hosting is almost tangible.

Why We Love the IT Support Career?
Why We Love the IT Support Career?

In almost all of my posts I was talking about the stressful side of the IT – the long hours, end user issues, migrations, midnight calls and the like. But...

IT Manager: Ways To Show Your Appreciation To Your Team
IT Manager: Ways To Show Your Appreciation To Your Team

Surely your team struggled hard and made things happen. You cannot say “this is what you get paid for” and just leave – you cannot keep your IT staff that...

Feeling Insecure In Your Current Job Position?
Feeling Insecure In Your Current Job Position?

Job security is one of our primary concerns. We everyday we live with the question of whether or not we will be working the next day. Loyalty is not the...

Leave a Reply

Your email address will not be published. Required fields are marked *