5 useful url rewriting examples using .htaccess

Now let’s look at the examples

1)Rewriting product.php?id=12 to product-12.html

It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.

RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1

2) Rewriting product.php?id=12 to product/ipod-nano/12.html

SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.

RewriteEngine on
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2

3) Redirecting non www URL to www URL

If you type yahoo.com in browser it will be redirected to www.yahoo.com. If you want to do same with your website then put the following code to .htaccess file. What is benefit of this kind of redirection?? Please check the post about SEO friendly redirect (301) redirect in php and .htaccess.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]

4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz

Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1

5) Redirecting the domain to a new subfolder of inside public_html.

Suppose the you’ve redeveloped your site and all the new development reside inside the “new” folder of inside root folder.Then the new development of the website can be accessed like “test.com/new”. Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it under the root folder of the website. In result, www.test.com point out to the files inside “new” folder.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1

Backtrack: http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html


  • Permanent link to this post Permalink 
  • Share this post! Share It! 
  • View this post's comments Comments (243) 
  • RSS Feed for this post's comments Comment RSS
  •    


Using MetaWebLog with PHP-XMLRPC

Due to the fact that there is virtually no documentation available on how to get the MetaWebLog API working with the PHP-XMLRPC library, I decided to write this post. The MetaWebLog API is an application programming interface that allows data to be passed from a client to a server, and vice versa. It is used by all of the most popular blogging software, allowing the user to post blog entries from software like Microsoft Word or Windows Live Writer.

If you want to add MetaWebLog functionality to your custom blog or CMS, then this post will really help you. First off, download the PHP-XMLRPC library and upload the three files - xmlrpc.inc, xmlrpcs.inc, xmlrpc_wrappers.inc - found within the lib folder to your web server.

With that done, you can now start implementing the MetaWebLog functions. The first one you’ll need to implement is blogger.getUsersBlogs, otherwise software like Microsoft Word won’t recognise it as a valid MetaWebLog implementation. With that done, you can then start working on the functions that you might need to use.

To debug your code, make sure you take advantage of the XMLRPC debugger. And for more information on what each function is supposed to accept and return, check out Microsoft’s MSDN.

Trackback: http://ryanhemelaar.blogsome.com/2009/01/29/using-metaweblog-with-php-xmlrpc/trackback/


  • Permanent link to this post Permalink 
  • Share this post! Share It! 
  • View this post's comments Comments (307) 
  • RSS Feed for this post's comments Comment RSS
  •    


About Me

Deepak Kamboj

Deepak Kamboj, MCTS, JCP
ASP.NET/C# Web Developer
Chandigarh, India

RSS Contact Twitter Facebook LinkedIn

Yahoo: DeepakKamboj@yahoo.com
GTalk: DeepakKamboj@gmail.com
Skype: DeepakKamboj

Recent Comments