SEO Friendly URLs

user-pic
Vote 0  

Filed:

 
Both User Profiles and Tags have mod_rewrite rules applied to them. This makes URLs much smaller, and much better for search engines.

Two "rules" generally apply. I know that not everyone will use these best practices but as authors and editors, we can do our best to set a good example.

Rule #1: Don't put spaces in your username or tags.
Rule #2: See Rule #1.

Lets take a look at some examples:

My profile URL looks like this:

http://bgviewsblogs.com/cgi-bin/mtcs/mt-cp.cgi?__mode=view&id=1

But after...

http://bgviewsblogs.com/profiles/meancode

Normally Tag search results look like this:

http://bgviewsblogs.com/cgi-bin/mtcs/mt-search.cgi?tag=bg-news

But after...

http://bgviewsblogs.com/tag/bg-news

If you use spaces in your username or tags, you get %20 (a URL encoded space) such as this:

http://bgviewsblogs.com/tag/bg%20news

How this is done:
In both cases, User Profiles and Tags, I did not want the results specific to any one Blog ID, so I took &blog_id=2 out of the rewrites. When I update the templates to use the rewritten URLs, I will omit &blog_id=2 as well. For the Tags, I will have a global tags page, so I did not want to constrain the results.

In your .htaccess file, add these lines (Note: there is no line break, it is just displayed on this page as such):

RewriteEngine on
RewriteRule ^profiles/(.*)$ /cgi-bin/mtcs/mt-cp.cgi?__mode=view&username=$1 [L]
RewriteRule ^tag/(.*)$ /cgi-bin/mtcs/mt-search.cgi?tag=$1 [L]


You could of course constrain any one of those rules to your liking, adding &blog_id=2.

One small issue:
If you notice there is a big difference between the original URL for my profile and the rewritten one (Original, Rewritten). For the rewrite I am using username=$1 and using username= instead of id= causes the custom fields to vanish. This is a known issue and I hope it gets resolved quickly.

You can always contact me here: webmaster [at] bgviews [dot] com.

Email to a friend

Anonymous comments are always moderated, please sign in and join the discussion. Create an account for a user profile and community features. Please read our comments policy.

Leave a comment

Poll

Do you like the toolbar at the bottom of this blog?

View results

View & Download PDF


View our support community!

About This Blog

Ken Edwards (and hopefully other project members) will be blogging here — a place to keep up on what is happening on the BG Views project. You will find bits of code, project updates, and random technical information aimed at confusing the hell out of you. More »

Subscriptions

Mobile Edition

Mobile EditionAccess the BG Views Developer Blog on your iPhone or other mobile device. Read more about our mobile site »
Powered by Movable Type 4.34-en

 

Also powered by:

  • Caffeine (Dr. Pepper)
  • Cup Cakes (Hostess)
  • Pizza (Pisanello's)