设置和放大器;阅读pretty的网址 [英] set & read pretty URL

查看:154
本文介绍了设置和放大器;阅读pretty的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这已经被广泛报道,但我似乎无法找到一个答案,我想做的事情。我读过的所有堆栈文章,看着不同的方法,谷歌展示了我已经试过搜索字符串的无限数量。

I know this has been covered extensively, but I can't seem to find an answer to what I want to do. I've read all the stack articles and looked at different methods that google shows with the infinite number of search strings I've tried.

我见过的文章谈到使得PHP读取URL去pretty的但没有(我可以理解)上使得pretty的去PHP读取。

I've seen articles talking about making the PHP readable URL go to pretty but nothing (I can understand) on making the pretty go to PHP readable.

我见过的文章在谈论让每一个用户一个htaccess项(在下面的情况下),但没有几行的解决方案,格式化,我需要的方式(同样,在下面的情况下)。

I've seen articles talking about making an htaccess entry for each "user" (in the case below), but no few-line solution that formats the way I need (again, in the case below).

有人可以提供一个模板:

Can someone provide a template for:

1)发送,看起来像 https://mysite.com/users/sampleUserName https://mysite.com/users.php?username=sampleUserName

1) Sending a pretty URL that looks like https://mysite.com/users/sampleUserName to https://mysite.com/users.php?username=sampleUserName

2)有users.php处理pretty的URL如果这甚至是必要的。

2) Have users.php handle the pretty url if that's even necessary.

我甚至完全确定我在问什么(因为我不知道如何工作的,因此这个问题),因此,如果任何人都可以更precisely读懂我的心思,这将是更AP preciated。 LOL

I'm not even totally sure what I'm asking (because I have no idea how this works hence the question), so if anyone can more precisely read my mind, it would be much appreciated. LOL

底线:我希望人们能在键入pretty的网址,让PHP能够处理它

Bottom line: I want people to be able to type in a pretty URL and have PHP be able to handle it.

提前感谢!

推荐答案

您需要使用Apache的的 的mod_rewrite

You need to use Apache's mod_rewrite.

您需要在您的的.htaccess 文件中添加以下行:

You will need to add the following lines in your .htaccess file:

RewriteEngine On
RewriteRule   ^[a-zA-Z0-9]/?$    users.php?username=$1    [NC,L]


如果您想了解更多关于它,这里是关于的 URL重写初学者

这篇关于设置和放大器;阅读pretty的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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