I have created a custom post type called 'event' and added an event called London 2012. I want the following URL structure for a page:


I have created a page called Speakers giving me a working /speakers url (I have Permalinks set to 'Post name').

Now I created a static test site and added the following to the .htaccess:

RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/speakers?$ /speakers.php [NC,L]

This meant that if I went to local.testsite.com/something/speakers it would display the content of speakers.php whilst retaining the orignal URL. Perfect! Or so I thought...

Now, having migrated the rule across to my Wordpress install (both by adding the rule in the .htaccess file directly - under the RewriteEngine on line - and through the add_rewrite_rule() function) I am getting strange behaviour.

RewriteRule ^([A-Za-z0-9-]+)/speakers/?$ /speakers?event=%1 [L]

Instead of the URL remaining the same and showing me the content of /speakers, it is actually redirecting me to the /speakers page and the URL is changing.

This is default behavior for a page in WP even without any modifications to the .htaccess file so I can only imagine that it is not matching my rule for some reason and then hitting the RewriteCond %{REQUEST_FILENAME} !-f line. Either that, or it is matching it but then continuing despite the [L] line.

Anyway I think that covers everything - if anyone has any ideas I'd really appreciate it as I'm going a bit crazy with this!

Update 1

Sorted - thanks Brian. Your solution did work but because the query variable was called 'event' it was getting confused and sending me to /speakers/ as a redirect. I changed it to simply be 'e' and it's fine now. Thanks again!


1 Answer 1


It looks like you need to process the rewrite using query strings rather than a URI segment and pass your query through index.php. WordPress seems to be agnostic of what you're trying to accomplish here.

Try the following rule and visit your Settings->Permalinks page to flush previous rules and add this to the stack.

    '^([A-Za-z0-9-]+)/speakers/?$', //Checked against the global $wp object - $wp->request
    'index.php?page=speakers&event=$matches[1]', //Use WP_Query params to find your page
    'top' //This will superceed the default WP rewrite stack

Make sure to register your query variable as well with WP so you can use it within $wp_query;

add_filter('query_vars', 'my_query_vars');
function my_query_vars($vars){
    $vars[] = 'event';
    return $vars;

You can then access your event query variable using the following:


For testing, I'm very fond of the Monkeyman Rewrite Analyzer plugin. It allows you to see behind the curtain of WordPress rewrites and assess which rules are matches, and how their query strings are fleshed out.

  • Thanks for your detailed response Brian. Acccording to Monkey Analyser it's now hitting the redirect correctly: ^([A-Za-z0-9-]+)/speakers/?$ page: speakers event: ([A-Za-z0-9-]+) HOWEVER the page it is showing isn't showing and post.
    – Joe Czucha
    Oct 20, 2012 at 2:00
  • 'HOWEVER the page it is showing isn't showing' sorry a bit confused by this. Do you mean you're getting a 404 error? Oct 20, 2012 at 2:48
  • Hi Brian, I've updated the original question with my findings. Thanks again for your help.
    – Joe Czucha
    Nov 12, 2012 at 17:19
  • Forgot to accept this but this ended up being a great solution, thanks Brian.
    – Joe Czucha
    May 6, 2013 at 20:01

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.