Search Engine Optimisation (SEO) Specialists

Link Rewriting for SEO

In this blog post I will be explaining how it is possible to re-write urls on an apache web server using your .htaccess file. This allows you to use ‘pretty’ links such as http://www.example.org/category/item.html in place of ‘ugly’ links such as http://www.example.org/catid=23&itemid=54

Aside from the fact that the pretty links obviously look better, they can help users navigate the site and are more search engine friendly. They provide keywords for the pages and can also provide a site hierarchy.

Some users navigate the site by removing sections of the URL, for example:

http://www.example.org/category/item.html -> http://www.example.org/category/

In a well designed site using URL re-writing this should not be a problem.

The Tutorial:

To get started, the below line should be added above the rewrite rules in your .htaccess file (if it is not there already) .
RewriteEngine on

We will assume that the sites URL’s are arranged as so:

http://www.example.org/index.php?pageid=x

http://www.example.org/index.php?catid=x

http://www.example.org/index.php?catid=x&itemid=y

In the sites database a field should be added to hold a ’slug’ – unique URL friendly title – for each page/category. The site linking needs to be changed so that the x/y above contains the slug e.g.

as well as the link

http://www.example.org/index.php?pageid=2

the following can be used:

http://www.example.org/index.php?slug=about-us

the argument in the url does not have to be slug, it could be anything e.g.

http://www.example.org/index.php?title=about-us

and so we have urls such as these:

http://www.example.org/index.php?slug=x

http://www.example.org/index.php?catslug=x

http://www.example.org/index.php?catslug=x&itemslug=y

Rewrite rules like these should then need to be added to the .htaccess file
RewriteRule ^([0-9A-Za-z-]+).html$ index.php?slug=$1 [L,QSA]
RewriteRule ^([0-9A-Za-z-]+)/$ index.php?catslug =$1 [L,QSA]
RewriteRule ^([0-9A-Za-z-]+)/([0-9A-Za-z-]+).html$ index.php?catslug =$1&itemslug=$2 [L,QSA]

In the
([0-9A-Za-z-]+)

regular expression, the brackets
()

select the regular expression between them.
[0-9A-Za-z-]

allows all alphanumeric characters and hyphens
(-)

we could add underscores
(_)

like this
[0-9A-Za-z-_]

for example.
The plus after the square bracket expression means 1 or more instances.
So
([0-9A-Za-z-]+)

looks for and selects a group of one or more alphanumeric characters/hyphens. The regular expression selects everything between the previous and next part of the link. So
^([0-9A-Za-z-]+).htm

Would select ‘abcdef’ from the url ‘http://www.example.org/abcdef.html’

This is just a very simple guide to regular expression, look out for an upcoming post explaining regular expressions in more detail.

The regular expression selection is referenced using
$1

, for each subsequent regular expression the number is incremented.

i.e.
RewriteRule ^([0-9A-Za-z-]+)/([0-9A-Za-z-]+).html$ index.php?catslug =$1&itemslug=$2 [L,QSA]

These above rules will then take a link such as

http://www.example.org/index.php?slug=about-us

and show

http://www.example.org/about-us.html

and

http://www.example.org/index.php?catslug=urls

and show

http://www.example.org/urls/

and

http://www.example.org/index.php?catslug=urls&itemslug=re-writing

and show

http://www.example.org/urls/re-write.html

The linking within the site should therefore be using the links of the format

http://www.example.org/urls/re-write.html

Each page should also automatically generate a canonical tag of the format
<link rel="canonical" href="http://www.example.org/url-of/page.html" />

at the top, therefore if any search engine spiders visit the existing links of the format http://www.example.org/index.php?catslug=urls&itemslug=re-writing they will know about the new link i.e. http://www.example.org/urls/re-write.html
and change the cached url to the new one.

Another example of re-writing

http://www.example.org/index.php?pageslug=x

http://www.example.org/index.php?catslug=x

http://www.example.org/index.php?itemslug=x

RewriteRule ^([0-9A-Za-z-]+).html$ index.php?slug=$1 [L,QSA]
RewriteRule ^category/([0-9A-Za-z-]+).html$ index.php?catslug =$1 [L,QSA]
RewriteRule ^item/([0-9A-Za-z-]+).html$ index.php?itemslug=$1 [L,QSA]

Will give urls such as

http://www.example.org/x.html

http://www.example.org/category/x.html

http://www.example.org/item/x.html

Discuss this blog in The Forum

Related posts:

  1. Search Engine Friendly URLs (Apache and PHP)
  2. Dynamic content rules
  3. Canonicalisation and SEO
  4. Are your URLs friendly?
  5. SEO and Joomla

Tags: , , , ,

Link to us

If you want to link to this blog, copy and paste the following HTML code to your website.

Leave a Reply

Search Blogs

Highest Rated Blogs

Tag Cloud

Recent Blogs

Blog Categories

About SEO
ASK SEO
Bing and Search Engine Optimisation
Black and White Hat SEO
Browser Software and Search Engine Optimisation
Cheap SEO
Clicktelligence & SEO
CMS and Admin Systems and SEO
eCommerce and Search Engine Optimisation
Email Marketing
Ethical Search Engine Optimisation
Flash and SEO
General SEO News
Geo Targeting Search Engine Optimisation
Google Analytics
Google and Search Engine Optimisation
Google PageRank
Google PR Update
Google Webmaster Tools
Increase Search Traffic with SEO
International SEO
Internet Marketing
Keyword Research and Search Engine Optimisation
Latest News
Link Campaigns and Search Engine Optimisation
Meta Tags and SEO
Mobile SEO
Offpage Optimisation
Online Advertising
Onpage Optimisation
Page Load and SEO
Page Rank Update
Pay Per Click & SEO
Press Releases
Professional SEO
Real Time Search
Search Engine Indexing and Crawling
Search Engine Optimisation
Search Engine Optimisation Advice
Search Engine Optimisation Analysis
Search Engine Optimization
Search Engine Optimization Keywords
Search Engine Optimization Marketing
SEO Analysis for Results
SEO and Business
SEO and Search Engines
SEO Blogging
SEO Companies
SEO Consult
seo consultancy
SEO Copywriting
SEO Costs
SEO Domain Names
SEO Experiment
SEO Links
SEO Lists
SEO Management
SEO Penalties
SEO Rankings
SEO Sitemaps
SEO Strategy
SEO Submissions
SEO Techniques
SEO Tips
SEO Tools
seo video
SEO vs PPC
Site Analysis and Search Engine Optimisation
Site Architecture & SEO
Social Media Optimisation
Social Networking and Search Engine Optimization
Target Marketing with SEO
Top SEO Tips
Traffic & SEO
Twitter and Search Engine Optimisation
User Driven SEO
W3C and Search Engine Optimisation
Web Design
Website Development
Website Optimization
Wordpress For SEO
Yahoo! and Search Engine Optimisation
View All Categories

Archives

Authors

W3C XHTML Valid W3C CSS Valid W3C WAI  Internet Marketing RSS Feed for SEO Consult