WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have custom post types registered and they are working fine with their normal URLs. My Custom post types have 'members' as their slug. Now I am trying to have a custom permalink for my custom post types. Here is my $wp_write->add_rule

$wp_rewrite->add_rule('members/.+?/(.+)/$','index.php?post_type=pasha_members&name=$matches[1]', 'top');

Below is my $wp_rewrite->rules array.

    ['members/.+?/(.+)/$'] => 'index.php?post_type=pasha_members&name=$matches[1]'
    ['category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$'] => 'index.php?category_name=$matches[1]&feed=$matches[2]'
    ['category/(.+?)/(feed|rdf|rss|rss2|atom)/?$'] => 'index.php?category_name=$matches[1]&feed=$matches[2]'

And here is the url that I am trying to access, I am not able to figure out what I am doing wrong.


When I change Permalink settings to default in Settings->Permalink, I can access the custom post just fine using the following url.


Let me know if you need more information. Any help pointers are much appreciated.

NOTE: I have put the add_rule in init instead of activate just for the testing. I also have put the flush_rewrite_rules in the init, its also temporarily until its fixed.

share|improve this question
up vote 2 down vote accepted

It appears that WordPress cuts off the final / before it starts matching the URL. So make it optional in the regex and it should work:


If the city and company parts will not contain slashes it could be even more clear to use [^/]+ to match them ("everything up to a slash"). Then your regex would become:


I created a plugin to analyze your rewrite rules, it is really easy to play with and debug your rules. Although you made me discover an error in it: it did not remove the final slash, so your first regex matched in my analyzer but not in the "real" WordPress. I'll update it soon!

share|improve this answer
Perfect!!! that did work. First I was using [^/]+ then I dropped it because I was not able to get it to work. Thank you. – Hameedullah Khan May 20 '11 at 7:47
One more question.. I want to reset the rewrite rules.. (i.e want wordpress to forget and then regenerate). so should I switch back to default in permalink settings and then back to custom. I think I messed up something now wordpress is going to home page for every url. – Hameedullah Khan May 20 '11 at 10:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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