1

I have a script, which automatically add a URL for every row I insert into database with php.

This is, how it works:

if (isset($_GET['name']) )
  $title = $_GET['name'];

 <Code to select and echo data from database here> 

So, if I insert a row named "UserA", then a URL will be created like this:

example.com/users/?name=UserA

I want to remove "?name="and make the URL like: example.com/users/UserA

Ravina Sharma
  • 51
  • 1
  • 8
  • possible duplicate of https://stackoverflow.com/questions/16388959/url-rewriting-with-php – Janen R Jun 08 '17 at 07:35
  • 1
    Possible duplicate of [URL rewriting with PHP](https://stackoverflow.com/questions/16388959/url-rewriting-with-php) – Janen R Jun 08 '17 at 07:35

2 Answers2

0

Try adding this to your .htaccess

RewriteEngine On RewriteRule /users/(.*)$ /users/name=$1

If you manage the server yourself, be sure to enable mod_rewrite.

0

If you are familiar with . htaccess then it's good, else create a file in your project folder called .htaccess where htaccess is it's extension not a name:

Then put this into the .htaccess file:

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^users/([0-9A-Za-z]+)/?$    users.php?name=$1    [NC,L]    # Handle product requests

This will enable a url rewrite rule and redirect request from users/name to users.php file where you can manage all the request.

Now by going through the url as users/name you will be able to show data from database about that user within the file users.php:

Note: .htaccess file is an APACHE server configuration file.

Syed Aqeel
  • 1,009
  • 2
  • 13
  • 36