问题
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
andphp.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!
回答1:
Well it would be much easier to do this with a .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^player/(.*)$ php.php?username=$1 [L,NC]
回答2:
The easiest and cleanest way is with .htaccess files, but if you don't want to, you can use PHP, what I'm not sure but this would help URL rewriting with PHP
来源:https://stackoverflow.com/questions/29106097/creating-a-fancy-url-with-php