且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 PHP 中传递页面时屏蔽 URL 的 $_GET 变量

更新时间:2023-02-25 14:56:13

您正在寻找使用 .htaccess 文件来重写 URL 的方法.例如,*** 可能会使用以下内容:

You're looking for using a .htaccess file to rewrite URL's. For example *** might use something like this:

RewriteEngine on
RewriteRule ^questions/([0-9]+)/([_\-\&\'\,\+A-Za-z0-9-]+)?$ questions.php?q=$1

这将使 ***.com/questsions/1234/a-title-of-a-page 和 ***.com/questions.php?q=1234 成为同一页面,因此在您的网站上,您需要使用网址的整洁"版本(第一个)

This would make both ***.com/questsions/1234/a-title-of-a-page and ***.com/questions.php?q=1234 the same page, so on your website you would need to use the "tidy" version of the URL (the first one)

可以阅读更多内容,您可以根据需要自定义您的 URL.例如,一些阅读它的地方包括:

A lot more can be read into this and you can customize you're URL's to what you require. For example, a few places to read up on it include:

http://httpd.apache.org/docs/2.0/misc/重写指南.html

http://www.easymodrewrite.com/

通常来说,这样做的一个好方法(这样您的 URL 中就没有很多 ID)是在您的数据库中存储页面的URL 友好"名称(例如页面名称"),然后当页面被请求时,只需在您的数据库中搜索该名称,您就会知道它与什么 ID 相关.

Generally a good way to do this (so that you don't have lots of ID's in your URL's) is to store a "URL friendly" name of the page (e.g. "name-of-page") in your database, then when the page is requested, just search your database for that name and you'll know what ID it relates to.