Switching to Permalinks
posted by Allan@TechCrammer @ 11:12pm, Tuesday 4 November 2008.
As I stated in my first blog, there were some features missing in the blogging software that I chose for this site, that wasn't quite sure I really needed. Well, I learned quickly that in order for search engines to find and crawl my blog with more ease, then I was supposed to use "Permalinks" or "Permanent Links".
Old way to link to articles:
http://www.techcrammer.com/news.php?id=8
New way to link to articles:
http://www.techcrammer.com/8.html
As you can see, this takes away some of the complexity with the "?id=8" and creating a user and search engine friendly URL.
Many blogs will use even more descriptive "pretty" URLs such as /category/date/article though this is my quick and easy fix for now. (Remember I am a bit lazy)
To implement this I simply added an .htaccess file in the document root as follows:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /news.php?id=$1 [L]
I found a website that provides an easier way to generate the .htaccess code for you if you are not a regular expression guru. http://www.generateit.net/mod-rewrite/
Ensure that you have the rewrite module in your Apache config. My httpd.conf line looks like this:
LoadModule rewrite_module modules/mod_rewrite.so
Also if you are using virtual hosts you may need a directory option with "Allowoverride" enabled.
The I just had to change around a few lines of PHP code to print the article links in the format of $id.html versus news.php?id=$id.
There are some other spots that may need this URL reformatted, though I believe I resolved the main areas that are more likely to be indexed.
Hmmm... it might be a nice option in the configuration to turn on/off permalinks.
Bring on the robots and crawlers!
-Allan








Comments
Submit Your Comment
You are not logged in.