0

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
2
  • what is game?
    – Milo
    Mar 4, 2014 at 15:14
  • Is game a post type or taxonomy? Have you enabled pretty permalinks in the admin area?
    – Tom J Nowell
    Mar 4, 2014 at 15:34

2 Answers 2

1

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.

0

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.

3
  • Unfortunately I've created a custom database 'game', where the data for each game is stored. Via $_GET['game'], I can request a custom page template and via the slug, create an instance of 'game' to display custom game data. Mar 4, 2014 at 15:22
  • So what do you do with WordPress?
    – fischi
    Mar 4, 2014 at 15:29
  • I like the login form and the plugins :D. Mar 4, 2014 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.