Support » Fixing WordPress » wordpress ignores the rewite rule

  • Alberto

    (@caseuniche)


    Hello

    here is the situation:
    in the functions.php file of the child theme there are these rewrite rules (regularly activated):

    add_rewrite_rule( '(vendita|affitto)\/(residenziale|negozio|attivita|ufficio)($|\/.*)', 'index.php?pagename=$matches[1]-$matches[2]', 'top' ) ;	// dedicated search pages for SEO
    add_rewrite_rule( '(vendita|affitto)\/..*|(cerca|ricerca|ricerche|search-property)($|\/.*)', 'index.php?pagename=ricerca', 'top' ) ;			// default search page

    when you use the link https://custaging.caseuniche.it/vendita/attivita/
    I expect the first rule (the one above) to send me back to the page
    https://custaging.caseuniche.it/index.php?pagename=vendita-attivita

    instead WordPress ignores the first rule (above) and applies the second (below)
    and send me here https://custaging.caseuniche.it/index.php?pagename=ricerca , the default search page

    What am I doing wrong ?

    I would like to go to the dedicated page of the first rule (above) which contains useful information for SEO
    even though the default search page reads the $ _SERVER ['REQUEST_URI'] and performs the search anyway.

    You can help me ?

    Alberto

    • This topic was modified 2 months ago by t-p. Reason: Moved to Fixing WordPress from Developing with WordPress

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Kuldeep

    (@soberbanda)

    Thread Starter Alberto

    (@caseuniche)

    Hello Kulepp,

    suggested topic do not give me more support:
    + first topic suggest to use function add_rewrite_rule() to control priority of added rule with ‘top’ as already done in my case
    + second topic suggest to use a plugin to check existing rules: rurrently I’m using Rewrite Rules Inspector and it confirm that my above rule could be used because no other rule match before it, see screenshot of used rules

    But … unfortunatelly in the use of link, as in my first description, WordPress apply the (second) rule below and ignores the fist one (above).

    please help me.

    Ciao,
    Alberto

    Kuldeep

    (@soberbanda)

    @caseuniche You need init hook. add_rewrite_rule is a core function.

    add_action(‘init’, function() {
    add_rewrite_rule(

    Thread Starter Alberto

    (@caseuniche)

    Kulldepp,
    thanks a lot for your effort for me 🙂

    you ara right add_rewrite_rule is a core function but,
    currentrly in my file functions.php
    add_rewrite_rule is used directly to define other rules
    and also both rules in this case are defined so (see in first description of topic).
    All defined rules work fine,
    also because the rules are copied to db when flush_rewrite_rules() run or when manually you save permaliks from admin menu (once is enough) and that was done.
    In fact WordPress use the second rule (below) properly, but I want it use the first one (above) and I doesnt !

    So in conclusion, unfortunatelly whe are stin on start point 🙁

    Anyway, thanks again for your help 🙂

    Someone else cne saupport us ?

    Ciao,
    Alberto

    Kuldeep

    (@soberbanda)

    Sorry for that @caseuniche 🙁

    Let’s wait for someone more experienced on this to help us out here.

    Thread Starter Alberto

    (@caseuniche)

    News

    a solution was inmplemented but … I didn’t understand why the old ones doesn’t work.
    In functions.php this code

    add_rewrite_rule( '(vendita|affitto)\/(residenziale|negozio|attivita|ufficio)($|\/.*)', 'index.php?pagename=$matches[1]-$matches[2]', 'top' ) ;	// dedicated search pages for SEO
    add_rewrite_rule( '(vendita|affitto)\/..*|(cerca|ricerca|ricerche|search-property)($|\/.*)', 'index.php?pagename=ricerca', 'top' ) ;	// default search page

    is now substituted with

    add_rewrite_rule( 'vendita/residenziale$', 'index.php?pagename=vendita-residenziale', 'top' ) ;	// dedicated search pages for SEO
    	add_rewrite_rule( 'vendita/negozio$', 'index.php?pagename=vendita-negozio', 'top' ) ;			// dedicated search pages for SEO
    	add_rewrite_rule( 'vendita/attivita$', 'index.php?pagename=vendita-attivita', 'top' ) ;			// dedicated search pages for SEO
    	add_rewrite_rule( 'vendita/ufficio$', 'index.php?pagename=vendita-ufficio', 'top' ) ;			// dedicated search pages for SEO
    	add_rewrite_rule( 'affitto/residenziale$', 'index.php?pagename=affitto-residenziale', 'top' ) ;	// dedicated search pages for SEO
    	add_rewrite_rule( 'affitto/negozio$', 'index.php?pagename=affitto-negozio', 'top' ) ;			// dedicated search pages for SEO
    	add_rewrite_rule( 'affitto/attivita$', 'index.php?pagename=affitto-attivita', 'top' ) ;			// dedicated search pages for SEO
    	add_rewrite_rule( 'affitto/ufficio$', 'index.php?pagename=affitto-ufficio', 'top' ) ;			// dedicated search pages for SEO

    add_rewrite_rule( ‘(vendita|affitto)\/..*|(cerca|ricerca|ricerche|search-property)($|\/.*)’, ‘index.php?pagename=ricerca’, ‘top’ ) ; // default search page`

    all wors fine now 🙂

    But why the old ones rule
    add_rewrite_rule( '(vendita|affitto)\/(residenziale|negozio|attivita|ufficio)($|\/.*)', 'index.php?pagename=$matches[1]-$matches[2]', 'top' ) ; // dedicated search pages for SEO
    is not the correct solution ?

    If someone can give us an explanation we can improve our understanding.

    Ciao,
    Alberto

    Kuldeep

    (@soberbanda)

    @caseuniche Great 🙂

    How did you come up with that solution though?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.