用 PHP 创建一个花哨的 URL [英] Creating a fancy URL with PHP

查看:17
本文介绍了用 PHP 创建一个花哨的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我继续问你我的问题之前,我知道互联网上有很多方法可以完成这种事情.我也明白这个过程被称为重写 url.但是,由于我不是编码专业人士,因此这些事情的过程似乎非常艰巨且难以理解.所以,我想我会向 StackOverflow 社区寻求帮助!

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!

这就是我想要的.目前,我有 2 个主要文件.

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

index.phpphp.php.

我的网站允许用户输入用户名并获取该用户名的信息.index.php 保存表单输入,php.php 处理实际的 PHP 代码.一旦用户提交了用户名,最后的 URL 将如下所示;

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

我希望上面的 URL 看起来像:

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

http://mcspy.info/player/_scrunch

这里有人可以指导我并以简单易懂的方式解释一下,我将如何做这件事?最好使用PHP!非常感谢!

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!

推荐答案

使用 .htaccess 文件会更容易:

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

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

这篇关于用 PHP 创建一个花哨的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆