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?
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]