0845 205 0292

Request A Free Website Analysis

Close

Link Rewriting for SEO

January 27th, 2010 by

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

This entry was posted on Wednesday, January 27th, 2010 at 12:00 pm . RSS GlobeYou can follow any responses to this entry through the RSS feed.

Link to us

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

Navigation

Blog Categories

Free SEO Analysis & Proposal

From The Blogread news

  • MAY 21
    There are a few common mistakes that people new to SEO often make.  Being relatively new to search engine optimisation myself, I try to avoid commenting on these issues unless I'm fully confident about the advice I'm giv...
  • MAY 19
    Quality content is crucial to search engine optimisation — if you've been reading this SEO blog for any time, you will know that I have tried to reinforce this point at every possible opportunity. One area I haven't cov...

Latest Newsread news

  • MAY 15
    With over 10million users in the UK and a somewhat eventful 12 months behind it, Twitter have finally agreed to work more closely with Government and policymakers in the UK. The Social Network currently has over 140million user...
  • MAY 14
    Following the recent Panda and Penguin updates recently, the content written for websites has become more of a focus; being more relevant and of better quality. Google is penalising content which is full of keywords to the point o...

Clients Say...

"We've long been considering an SEO campaign and have researched the benefits that it could potentially bring to our web presence," commented 3663 Catering Equipment's Managing Director Paul Knight. "The team at Click Consult put together a very attractive package and we're pleased to be able to enter into a sound business partnership with them. We're looking forward to seeing the results they can provide for the 3663 Catering Equipment website moving forward."

3663

Managing Director - 3663 Catering

"We have been working with Click Consult for over a year now. We are delighted with the increase in unique visitors to our site and they have far exceeded our conversion KPI metrics for customer database registrations. We rank in the top 3 for all keywords that we asked Click Consult to optimize for us. This agency know how to produce results."

hills pets

Managing Director - Liverpool One

"Whilst we have a long term keyword strategy, Click Consult have a good appreciation of our business and have a flexible approach to implementing short term keyword strategies to coincide with the peaks of the retail calendar. I receive a monthly performance report from Click Consult detailing the relevant data I require but in addition, I can review the work being undertaken at any time by logging in to their bespoke reporting system."

hills pets

CRM Manager - Liverpool One

"Hills has been looking for an agency that is able to quickly deliver in the search marketing area and catapult EMEA websites ahead of the competition. Taking SEO Consult for this project turned out to be a smart choice. Not only have they managed to significantly increase search engine traffic to our websites, but they also come with innovative ideas that can be turned to reality. I can simply say they deliver. And it's always a pleasure talking to them."

hills pets

Managing Director - Hills Pets