Wordpress custom Querystrings & Pretty URL's - How? Wordpress custom Querystrings & Pretty URL's - How? wordpress wordpress

Wordpress custom Querystrings & Pretty URL's - How?


Don't add the rewrite rule to your .htaccess file. WordPress manages that file for you, so try to use built-in features whenever you can.

WordPress actually has a somewhat advanced rewrite engine that ships standard - and it's pluggable just like the rest of the platform.

The trick, though, is working with it. You'll need to register your RegEx so WordPress knows what kinds of strings to match (i.e dynamic/location/(.*)/code/(.*) => /dynamic?$loc=$1&code=$2). Then you'll need to set up the page and script on the back end to handle the submission.

For a similar example, look at the answer I received to parsing custom URLs with a custom post type over on WordPress Answers. Extending this, you'll need to set up code similar to the following (note: untested!!!):

<?phpadd_action('init', 'add_my_rewrite');function add_my_rewrite() {    global $wp_rewrite;    $wp_rewrite->add_rule('location/([^/]+)/code/([^/]+)','index.php?loc=$matches[1]&code=$matches[2]','top');    $wp_rewrite->flush_rules(false);  // This should really be done in a plugin activation}

This should add the rewrite structure to your .htaccess file automatically.