November 30, 2008

Expression Engine and Google friendly links

Article about ▸

written by Marek Foss

We all know that Search Engine Optimization (SEO) is very important. When I am looking for something on the web, I generally don’t ask around or look through link directories — I do a quick search on Google. So the higher something appears in the search list, the better for that page’s author. Cause I’m most likely to click that, not the one that is 20 pages later. Therefore, it is important how you present your content and how you link to it (because Google collects links and ranks the content). Expression Engine (EE) can’t do much about your content, but has by default, a very nasty, search-engine unfriendly way of creating links. Let’s fix it.

If you look at your website URL you will see that each entry has a link with a lot of unnecessary stuff.

Nasty URL:

http://yourdomain.com/index.php/site/entry/entry-title

Not only you have index.php explicitly, you also get the template group name site. It’s even worse when you list all entries form a category, because you get vague category identifiers, like C4 etc. But it can all be changed.

First, this article describes in details how to remove the index.php and the template group name. Long story short (that worked for me) is to download the LG .htaccess Generator and make some modifications to the initial .htaccess template you’re presented with. The .htaccess file will handle the process of rewriting the search-engine friendly URL to something EE understands. So now, you’ll be able to use entry links like the following:

Pretty URL:

http://yourdomain.com/entry/entry-title

But before that, note 2 things. One is that the LG .htaccess Generator appends the generated code to the .htaccess file — so you’d better remove it and create a blank one every time you want to re-generate it. Second things is that strangely, the default rewrite rules didn’t work quite well for me. I had to modify them to stop getting Internal Server Errors, as well as to remove the nasty index.php appearing in the front page URL after it was stripped from the www prefix.

My .htaccess rules:

# Dont list files in index pages
IndexIgnore *

RewriteEngine On

RewriteBase /

# Remove the www
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]

# Rewrite homepage urls that have the Google Analyticis query string
# CampaignMonitor adds the query string in their emails
# "site" is the template group
# "index" is the template name
# The template group and template should point to your sites index
RewriteCond %{QUERY_STRING} ^utm_medium
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule (.*) /index.php?/pages/index/&%{QUERY_STRING} [L]

# Add a trailing slash to paths without an extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [L,R=301]

# Remove index.php
# Uses the "include method"
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/({ee:template_groups}|{ee:pages}|members|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /index.php?$1&%{QUERY_STRING}

All what is left to do is to change the paths accordingly, so that you don’t have the index.php everywhere. Go to Admin - System Preferences - General Configuration and remove the name of your index page, leave the field blank. Then go to Admin - Weblog Administration - Weblog Management - Edit Preferences - Path Settings, and remove the index.php and template group name from these URLs — except the search address. Also, remove the {my_template_group} from links in your template.

The last step is to make categories more readable. Go to Admin - Weblog Administration - Global Weblog Preferences and set Use Category URL Titles In Links? to Yes. Then choose your keyword for the categories, i.e. category, in Category URL Indicator — your category links will appear like that:

Pretty category URL:

http://yourdomain.com/category/category-name

And that’s it. Now your links look nice, just like mine on this blog. Just read some about SEO, because the content optimization is all in your hands.


If you liked the article, please spread the word and share it!

  • Share

Comments


Kurt Munro writes:

Or just use Textpattern and go to options and select from 5 or so different URL styles :P

If only we could merge all the CMS’s into one…



Leave a comment: (comments may not appear immediately due to page caching)

Name: Email: (not disclosed)

WWW: Remember my details

Notify me of follow-up comments

Feed me:

to feed
  • Subscribe and get the new articles every now and then directly in your reader — I recommend using Google Reader

Facebook:

Connect:

 by Google
Google FriendConnect appears to be down at the moment. Sorry for inconvenience.
Related Posts with Thumbnails