I have this url:
http://sitename.com/?game=runescape
Is it possible to modify the htaccess file or rewrite the url via Wordpress to become like this:
http://sitename.com/game/runescape
First, add a WordPress page named game
to direct requests to.
Next, add the game
query var so WordPress knows what it is:
add_filter( 'query_vars', 'wpa_query_vars' );
function wpa_query_vars( $query_vars ){
$query_vars[] = 'game';
return $query_vars;
}
Then, add a rewrite rule to handle the incoming requests and direct them to your page:
add_action( 'init', 'wpa_add_game_rule' );
function wpa_add_game_rule() {
add_rewrite_rule(
'game/([^/]+)/?',
'index.php?pagename=game&game=$matches[1]',
'top'
);
}
Last, create a template named page-game.php
and add get_query_var( 'game' )
to see the requested game.
Just go to "Settings"=>"Permalinks" and check the option "Post Name".
WordPress handles the rest for you. If game
is a custom post type, you do not need to do anything else.
EDIT:
As you mentioned that game
is a script outside WordPress, this question is out of scope for this community.
game
?game
a post type or taxonomy? Have you enabled pretty permalinks in the admin area?