• Resolved ExcellentSP

    (@siphon)


    It’s just as the title says, I have this:

    function add_new_rewrite_rules() {
      add_rewrite_rule( 'colorado-springs/?$', 'index.php?page_id=2&qlocation=colorado-springs', 'top' );
    }
    add_action( 'init', 'add_new_rewrite_rules' );

    And whenever I type in, “http://domain.com/colorado-springs”, then hit enter, I’m directed to the home page, which is good, but then it removes the slug. So the result of me entering that slug is this: http://domain.com/.

    If I rewrite to a different page ID, this works and the slug stays put. For example:

    function add_new_rewrite_rules() {
      add_rewrite_rule( 'colorado-springs/?$', 'index.php?page_id=7&qlocation=colorado-springs', 'top' );
    }
    add_action( 'init', 'add_new_rewrite_rules' );

    Is this something that anyone else is struggling with?

    PS: Hard coded values are only for display purposes.

Viewing 1 replies (of 1 total)
  • Thread Starter ExcellentSP

    (@siphon)

    Answered my own question:

    function prefix_disable_canonical_front_page( $redirect ) {
        if ( is_page() && $front_page = get_option( 'page_on_front' ) ) {
            if ( is_page( $front_page ) )
                $redirect = false;
        }
    
        return $redirect;
    }
    
    add_filter( 'redirect_canonical', 'prefix_disable_canonical_front_page' );

    But I still wonder if there are SEO implications.

Viewing 1 replies (of 1 total)

The topic ‘How to use add_rewrite_rule() on the home page ("/")…’ is closed to new replies.