Support » Plugins » rewrite rule not working

  • Hi,
    I’m adding some rewrite_rules to provide more SEO friendly urls for my plugin page.
    I’m trying to match an url like this:
    http://mysite.com/2-bedrooms/3-bathrooms/mycity/2.html
    that means the user is looking for a house with 2 beds, 3 baths, placed on mycity and he is requesting the page 2. This url is then translated to a regular querystring-based url.
    Here is my code to add my rules:

    function insert_rewrite_rules( $rules ) {
    	$newrules = array();
    	$page_name = 'mypage';
    
            //basic rule
    	$newrules['(' . $page_name . ')$'] = 'index.php?pagename=$matches[1]';
    
    	//search by id
    	$newrules['(' . $page_name . ')/(\d+)$'] = 'index.php?pagename=$matches[1]&id=$matches[2]&search=1';
    
    	//url with page included
    	$newrules[(mypage)(/(\w+)-bedrooms)*(/(\w+)-bathrooms)*/([^.]+)/(\d+).html$'] = 'index.php?pagename=$matches[1]&bedrooms=$matches[3]&bathrooms=$matches[5]&query=$matches[6]&page=$matches[7]';
    
            //url with no page
    $newrules[(mypage)(/(\w+)-bedrooms)*(/(\w+)-bathrooms)*(/([^.]+))*$'] = 'index.php?pagename=$matches[1]&bedrooms=$matches[3]&bathrooms=$matches[5]&query=$matches[7]';
    	return $newrules + $rules;
    }
    add_filter( 'rewrite_rules_array','insert_rewrite_rules' );

    The rules are well saved, this is not the problem.
    But redirection is not working at all. I’m able to match the url without the page (http://mysite.com/2-bedrooms/3-bathrooms/mycity), but when I add the “/2.html” wp doesn’t understand it and redirect me to http://mypage.com/2/, then this url is interpreted applying the rule of “search by id”, mentioned above.
    I recently moved to wp version 3.4.1, in version 2.9.2 it worked just fine.

    All I need is a regex to match with the above given url, including the current page.
    Please, give me some hints.
    Thanks in advance

  • The topic ‘rewrite rule not working’ is closed to new replies.