如何从PHP脚本改变外观的URL [英] How to change appearance of URL from within a PHP script

查看:319
本文介绍了如何从PHP脚本改变外观的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一个文件中的一些PHP和HTML,我不完全知道如何使URL显示为该网页的名称。

I have some PHP and HTML in the same file, and I am not exactly sure how to make the URL appear as the name of that page.

下面是什么,我想办一个例子:让我们说一些页面的id = 1,而网页的标题的HelloWorld

Here is an example of what I would like to do: lets say some page id = 1 and the title of that page is HelloWorld.

而不是 site.com/page.php?id=1 的我想的网址显示为 site.com/HelloWorld

Instead of site.com/page.php?id=1 I would like the url to appear as site.com/HelloWorld

但我遇到的问题是,我只了解页面的标题,内页后,我查询通过ID称号。

But the problem I am having is that I only get to know the title of the page inside that page after I query for the title by id.

考虑到我所描述的设置,有没有一种方法,使网址出现在页面的名称?而且,如果有人通过使用更好看的URL的网页,而不是ID的名称链接到网页,有仍然有办法让id和由,页面内容的休息吗?

Considering the setup I described, is there a way to make the urls appear as the names of the pages? And also, if someone links to that page by using the better looking url with the name of the page instead of the id, is there still a way to get the id and by that, the rest of the page contents?

谢谢!

推荐答案

您需要做的是了解更多关于如何的.htaccess的工作。

What you need is to learn more on how .htaccess work.

下面是让我开始了一个很好的链接:

Here is a good link that got me started:

的.htaccess技巧和提示

更新:

下面是所有请求被发送到index.php文件在很多框架中非常普遍的做法,并从那里你使用PHP来服务于正确的页面:

Here is a very common practice in many framework where all requests are sent to index.php, and from there you use php to serve the correct page:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://www.site.com/index.php [L,R=301]
</IfModule>

这篇关于如何从PHP脚本改变外观的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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