在 PHP 中传递页面时屏蔽 URL 的 $_GET 变量
我正在尝试使我的网站 SEO 和用户友好的 URL.它基本上是一个静态的公司网站,但对于侧边菜单,我通过 URL 传递了一些变量以显示主选定菜单的子菜单.
I'm trying to make the URLs of my site SEO and user friendly. It is basically a static corporate website but for the side menu I am passing some variables through URL to show the sub menu of main selected menu.
例如:离岸人员配备是主菜单项之一,其子菜单项之一是程序员.当有人点击 Programmers 时,我会通过 URL 传递主菜单和子菜单的 id 来折叠所有其他菜单并提升打开的菜单.
For example: Offshore staffing is one of the main menu items and one of its sub menu items is Programmers. When someone clicks Programmers I will pass the id of main menu and sub menu through URL to collapse all other menus and promote the opened menu.
我想在每个 URL 的末尾屏蔽类似 ?id=4&sid=4
的内容.无法使用隐藏的输入元素,因为我正在修改此站点,而实际构建该站点的开发人员并未使用表单.
I want to mask something like ?id=4&sid=4
at the end of every URL. Can't use hidden input element because I am modifying this site and the developer who actually built that site didn't use forms.
您正在寻找使用 .htaccess 文件来重写 URL 的方法.例如,stackoverflow 可能会使用以下内容:
You're looking for using a .htaccess file to rewrite URL's. For example stackoverflow might use something like this:
RewriteEngine on
RewriteRule ^questions/([0-9]+)/([_\-\&\'\,\+A-Za-z0-9-]+)?$ questions.php?q=$1
这将使 stackoverflow.com/questsions/1234/a-title-of-a-page 和 stackoverflow.com/questions.php?q=1234 成为同一页面,因此在您的网站上,您需要使用网址的整洁"版本(第一个)
This would make both stackoverflow.com/questsions/1234/a-title-of-a-page and stackoverflow.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.