Forum Moderators: phranque

Message Too Old, No Replies

Using PHP to do mod-rewrite

         

akreider

9:23 pm on Mar 14, 2006 (gmt 0)

10+ Year Member



What is the best way to use php to do mod_rewrite?

For instance, I have several thousand users and I want to give them their own URLs instead of using user-1.htm as their page.

I know I'll need a table to store this information.

My problem is that I don't know how to get php to do the rewriting, and how php might need to interact with the .htaccess file so that php gets the chance to rewrite.

Ex. if someone visits my links.htm page, I want them to stay there. If they visit my /users/ilovecheese/ page them I want to redirect them to /users/user-10.htm.

Aaron

AjiNIMC

7:18 am on Mar 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You assign the urls(user friendly) to the different pages and then using .htaccess direct them using different variables.

Example

/users/ilovecheese/ to /users/user-10.htm (rigth)

in .htaccess you can say,

RewriteCond %{REQUEST_URI}!/users/(.*)\.htm
RewriteCond %{REQUEST_URI} /users/(.*)
RewriteRule /users/(.*) /detectuserID.php?username=$1[QSA,L]

and inside detectuserID.php you are getting $_GET['username'] and then search the username inside DB, get the userid and redirect them to /users/user-ID.htm

again you can write
RewriteCond %{REQUEST_URI} /users/user-(.*)\.html
RewriteRule /users/user-(.*)\.html /displayuserdetails.php?userid=$1[QSA,L]

I am in a hurry so I might have messed few things but I think this will atleast give you a direction.

Thanks,
AjiNIMC