0

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:

    add_rewrite_rule(
    "foto/([^/]+)/([^/]+)/?([0-9]{1,})/?",
    "index.php?fotograf=$matches[1]&gallery=$matches[2]&img=$matches[2]",
    "top");

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!

2
  • 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
    Commented Apr 16, 2016 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? Commented Apr 16, 2016 at 21:47

1 Answer 1

0

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;  
  }
  add_filter('generate_rewrite_rules','gallery_rewriterules');

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.