pretty从数据库的URL [英] Pretty URLs from DB
问题描述
我正在从数据库建立网页链接,如下面的例子。
I am working on creating page links from DB like the following example.
当前页:
www.example.com/page.php?pid=7
在DB它保存为标题为接触我们类下的公司信息
In the DB it is saved as title "contact-us" under category "Company Info"
我想这是这样的:
www.example.com/company-info/contact-us.html
我曾尝试不同的解决方案和答案,但并未有任何运气。我不知道,这里将是PHP的一部分,而哪些规则写入.htaccess文件。
I have tried different solution and answers but did not got any luck. I am not sure, where will be the PHP part and which rules to write for .htaccess files.
推荐答案
如果你想找到的网址这个页面,你可能会通过PHP和htaccess的做到这一点。使调用 page.php
为每个请求的.htaccess。你并不需要在 PID = 7
,因为,在的.htaccess怎么会知道这是7,对不对? :)
If you want to find this page by url, you will probably do this through php and .htaccess. Make a .htaccess that calls page.php
for each and every request. You don't need the pid=7
, because, well, how should the .htaccess know it is 7, right? :)
在page.php,你把原来的URL并把它分解的斜线,所以你得到的类别(公司信息
)和页面本身(接触us.html
)。然后,您可以在数据库中查找这些了。这是概括地说有多少软件作品,包括维基百科(链接到MediaWiki)和codeIgnitor。
In page.php, you take the original url and split it on the slashes, so you get the category (company-info
) and the page itself (contact-us.html
). Then, you can look these up in the database. This is in a nutshell how many software works, including Wikipedia (MediaWiki) and CodeIgnitor.
记住,公司信息是不一样的公司信息。你必须指定数据库的URL版本才能够使用它的查询。
Mind that 'company-info' isn't the same as 'Company Info'. You'll have to specify the url-version in the database to be able to use it for look-up.
这篇关于pretty从数据库的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!