• Hello!

    I would like to use the php add_rewrite_rule function, but is very difficult for me getting the regex expression.

    This are some examples of the regular expressions I’m trying to get:

    compare-nikon-d500-with-canon-eos-1200d –> compare/?c1=nikon-d500&c2=canon-eos-1200d

    compare-panasonic-lumix-dmc-50-with-sony-a500 –> compare/?c1=panasonic-lumix-dmc-50&c2=sony-a500

    Please, can you help me?

    Thanks and sorry about my english

Viewing 2 replies - 1 through 2 (of 2 total)
  • #^/compare-([a-z0-9-]+?)-with-([a-z0-9-]+)/?$#i so c1 and c2 will be in matches[1] and matches[2] respectively.

    Thread Starter ricardo.carrillo

    (@ricardocarrillo)

    Thank you for the answer, Konstantin.

    This is the code in my functions.php

    function custom_rewrite_basic() {
      global $wp_rewrite;
      add_rewrite_rule('^/comparar-([a-z0-9-]+?)-con-([a-z0-9-]+)/?$', '/comparar/?c1=$matches[1]&c2=$matches[2]');
      $wp_rewrite->flush_rules( false );
    }
    add_action('init', 'custom_rewrite_basic');

    But it should be something wrong because is not working. Any idea?

    Thanks again

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Regex expression’ is closed to new replies.