如何从PHP脚本改变外观的URL脚本、外观、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 p...

我在同一个文件中的一些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>
阅读全文

相关推荐

最新文章