Creating a fancy URL with PHP

谁说胖子不能爱 提交于 2019-12-08 06:01:36

问题


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!


回答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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!