Is it possible to hide one of the GET variables through .htaccess redirect?

混江龙づ霸主 提交于 2019-12-12 03:46:15

问题


Suppose I am passing 4 variables through get method, say game_name, game_id, game_category, game_player.

the default link would look something like this: www.games.com/gameinfo?game_name=zxcvb&game_id=12345&game_category=foo&game_player=bar

Now, I want to rewrite the URL like: www.abc.com/gameinfo/foo/zxcvb/bar

I do not want to show the id of the game in the link but still want to get it passed using GET method.

How can this be done?


回答1:


Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# From: /gameinfo/12345/foo/zxcvb/bar
# To: /gameinfo?game_name=zxcvb&game_id=12345&game_category=foo&game_player=bar

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(gameinfo)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /$1?game_name=$2&game_id=$3&game_category=$4&game_player=$5 [L,QSA,NC]


来源:https://stackoverflow.com/questions/17566342/is-it-possible-to-hide-one-of-the-get-variables-through-htaccess-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!