Masking $_GET variables of the URL when passing pa

2019-09-13 05:14发布

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.

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.

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.

标签: php url
3条回答
戒情不戒烟
2楼-- · 2019-09-13 05:35

What do you mean by "masking"? Is URL-rewriting, what you are searching for? If yes, you need to append the alias (e.g. "programmers") to the URL, instead of the GET-params. Those will be translated to GET-params via URL-rewriting and then matched to an ID via PHP.

查看更多
成全新的幸福
3楼-- · 2019-09-13 05:37

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

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)

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/rewriteguide.html

http://www.easymodrewrite.com/

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.

查看更多
孤傲高冷的网名
4楼-- · 2019-09-13 05:43

Translate the ID's to the words they stand for when writing the links, and use mod_rewrite to pass them back to PHP when they're visited, where you do a lookup based on the words, and find the ID again.

So the link becomes /offshore/programmers, then you do a lookup for the ID's of "offshore" and "programmers" and show the appropriate content.

查看更多
登录 后发表回答