I am trying to create the SEO friendly URL: http:///foto/linse2-at/linse2-at-schloss-altenhof/2618

for this one: http:///?fotograf=linse2-at?gallery=linse2-at-schloss-altenhof&img=2618

For my logic, this code should work:


But the the rule generated is (dump of global $wp_rewrite):

[foto/([^/]+)/([^/]+)/?([0-9]{1,})/?] => index.php?fotograf=&gallery=&img=

..which does not work.

It seems that the "$matches[1]" are missing.

Thanks for your input!

  • what are fotograf, gallery, and img? Are those registered query vars? Rewrite rules have to result in a successful main query that loads some type of WordPress object- a page, a post, an archive. – Milo Apr 16 '16 at 16:24
  • Thanks for the hint. Maybe this is why the rewrite rule does not work. "fotograf" mapps to a custom content type. "gallery" and "img" are not directly a "WordPress object" they are only HTTP-GET parameters, which are used on the fotograf-page: single-fotograf.php. Is this really a the reason why the rewrite rule does not work? – user3735572 Apr 16 '16 at 21:47

Updating the rewrite-rules manually as follows worked for me:

 function gallery_rewriterules( $wp_rewrite ) {

  $new_rules = array( "hochzeitsfotografen/([^/]+)/([^/]+)/?([0-9] {1,})/?" => "index.php?fotograf=".$wp_rewrite->preg_index(1)."& gallery=".$wp_rewrite->preg_index(2)."&img=".$wp_rewrite->preg_index(3));
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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