Search code examples
phpurlrewriting

Creating a fancy URL with PHP


Before I go ahead and ask you my question, I understand that there are many methods on the internet to accomplish this sort of thing. I understand also that this process is called rewriting urls. However, since I am not a proffesional at coding, the process of these things seem very daunting and hard to understand. So, I thought I'd ask the StackOverflow community for help!


Here's what I'd like. Currently, I have 2 main files.

index.php and php.php.

My site allows users to enter a username and get information for that username. index.php holds the form input, and php.php handles the actual PHP Code. Once a user has submitted the username, the URL at the end will look like this;

http://mcspy.info/php.php?username=_scrunch

What I'd like the URL above to look like is:

http://mcspy.info/player/_scrunch

Could somebody here please guide me and explain in an easy manner to understand, how I would go about doing this? Preferably using PHP! Thanks a lot!


Solution

  • Well it would be much easier to do this with a .htaccess file:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^player/(.*)$ php.php?username=$1 [L,NC]