You can do this with the internal rewrite system, which is parsed in php, not htaccess.
First, add the rule. This assumes you have created a root page under Pages
with the slug dictionary
.
function wpd_dictionary_rewrite(){
add_rewrite_tag( '%dictionary_word%', '([^/]+)' );
add_rewrite_rule(
'^dictionary/([^/]+)/?$',
'index.php?pagename=dictionary&dictionary_word=$matches[1]',
'top'
);
}
add_action( 'init', 'wpd_dictionary_rewrite' );
This code would go in your theme’s functions.php
file, or your own plugin.
Visit the Settings > Permalinks
page to flush rules after adding this.
Now you can visit site.com/dictionary/word
and the requested word will be available in the template with get_query_var('dictionary_word')
.
If the code relies on $_GET['w']
and you can’t / don’t want to change this, you can hook before the code runs and set the value manually:
function wpd_set_dictionary_word(){
if( false !== get_query_var( 'dictionary_word', false ) ){
$_GET['w'] = get_query_var( 'dictionary_word' );
}
}
add_action( 'wp', 'wpd_set_dictionary_word' );