Recent Posts

This Post Has Been Viewed 579 Times.

Url rewriting examples using .htaccess

Posted by admin | Posted in Apache, PHP | Posted on 11-03-2009

4

Hi here i will explain some URL rewriting magic using .htaccess file.
1)Rewriting user.php?id=12 to user-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 ^user-([0-9]+)\.html$ user.php?id=$1

2) 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

VN:F [1.5.7_846]
Rating: 10.0/10 (1 vote cast)
VN:F [1.5.7_846]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • Xerpi

Related posts:

  1. Disable the TRACE and TRACK For More Security
  2. Speed up wordpress using .htaccess part 2
  3. Search Engine Friendly URL Using mod_rewrite

Comments (4)

how’re you doing guys?

VA:F [1.5.7_846]
Rating: 0.0/5 (0 votes cast)
VA:F [1.5.7_846]
Rating: -1 (from 1 vote)

Amazing !!!!

VA:F [1.5.7_846]
Rating: 0.0/5 (0 votes cast)
VA:F [1.5.7_846]
Rating: -1 (from 1 vote)

Hello all
I am new to this board but this is superbbbbbbbbbbbbb

VA:F [1.5.7_846]
Rating: 0.0/5 (0 votes cast)
VA:F [1.5.7_846]
Rating: -1 (from 1 vote)

Hello all
I am new to this board, a good one.

VA:F [1.5.7_846]
Rating: 0.0/5 (0 votes cast)
VA:F [1.5.7_846]
Rating: -1 (from 1 vote)

Write a comment

Spam Protected