0

I have a website, say its

http://www.mywebsite.com

now I can show the user information if i do something like

http://mywebsite.com/user.php?name=John

i use php to query database to generate user information into an html page

But how can i do it like

http://www.mywbsite.com/john

do i create a page for each and every user i have ? or is there a better way

user780277
  • 81
  • 1
  • 4

2 Answers2

0

This is the basic rule to hide user.php?name= from the URL. Put this in your root .htaccess file.

mod_rewrite must be enabled with PHP and this will work for the PHP version higher than 5.2.6.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ user.php?name=$1 [L]
Yasii
  • 1,702
  • 1
  • 10
  • 15
0

you can use .htaccess like this

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ user.php?name=$1 [QSA]

and then for get user

<?php 
 $user = $_GET['name'];
?>