Create your own URL Shorten-er for Wordpress

by Shabbir on January 4, 2010

in Blogging, CMS

Twitter has ignited new era, an era of URL shorten-er service like tinyurl or bit.ly and many more but then I was thinking about doing something of my own. No no no don't worry it is not yet another URL shorten-er service but it will be to make your Wordpress URL's shorter and using your own domain name in it. If you are using hosted Wordpress blog and have some permalinks structure defined you will have the following in your .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Now add the following just above that.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^codeitwell\.com$ [NC]
RewriteRule ^([0-9]+)([\/]?)$ http://www.codeitwell.com/?p=$1 [S=1]
</IfModule>

It assumes that your non-www version of the url does not have anything and can be used for URL shortening. If not you can create any other sub-domain for the same. Remember to change codeitwell.com to your domain name.

Example

codeitwell.com/1449

Explanation

RewriteCond %{HTTP_HOST} ^codeitwell\.com$ [NC]

Only Applies the RewriteRule for non-www host. This is optional line and can be avoided. If you avoid this line the redirect will work for all hosts. i.e. www and non-www.

RewriteRule ^([0-9]+)([\/]?)$ http://www.codeitwell.com/?p=$1 [S=1]

Checks if its only numbers and redirects to the post URL. Remember [S=1] is very important because it skips the next RewriteRule which is for the default Wordpress permalinks rule which need not be executed any more.

Share:
  • Digg
  • Facebook
  • StumbleUpon
  • Technorati
  • Twitter
Other Related Posts:
  1. Blogspot Vs Wordpress
  2. SEO for Wordpress Categories
  3. Wordpress as CMS
  4. AWeber Footer SlideUp – My First Wordpress Plugin
  5. 20 Essential Wordpress Plugins

Want More Tips on How to Make Money Online?
Enter your Name and Email below to subscribe and start 1 month free course now.

Name:
Email:
You would require to confirm your email address before we send you any updates. We respect your privacy as much as you do.
Powered by Aweber
  • codeunlock
    This is something very interesting. Thanks for sharing.
  • The pleasure is all mine
blog comments powered by Disqus

Previous post:

Next post:

    About the Author

  • author photo

    My Name is Shabbir Bhimani and I am developer by profession in the field of applications, web and database. Currently doing full time online marketing and like to share my experiences on how you can make money online @ CodeItWell.com. Read more ...


    See how you can get in touch with me.