简体   繁体   中英

WordPress query string to change SEO friendly URL

I want to create SCO friendly URL in the WordPress. Also, I have added a hook in my functions.php file as below code but not working.

My URL: http://bddlabs.com/webinar01/?id=pzlyglhbepotwpvbigdatadim_data&storyid=Story_997e9391-71d7-4fac-804b-de891c7aa595

I want http://bddlabs.com/webinar01/pzlyglhbepotwpvbigdatadim_data/Story_997e9391-71d7-4fac-804b-de891c7aa595

Is it possible? I am not sure about it. URL query string is coming from the third party, URL query string is coming from the third party, page content render based on query string.

Below code added landing-page-15.php it WordPress theme base page template

function fb_change_search_url_rewrite() {
    if ( ! empty( $_GET['storyid'] ) ) {
        wp_redirect( home_url( "/webinar01/" ) . urlencode( get_query_var( 'storyid' ) ) );
        load_template( realpath(__DIR__ . '/..') . '/landing-page-15.php' );        
        exit();
    }   
}
add_action( 'template_redirect', 'fb_change_search_url_rewrite' );
//additional rewrite rule + pagination tested
function rewrite_search_slug() {
    set_query_var('storyid', $_GET['storyid']);
    add_rewrite_rule(
        'find(/([^/]+))?(/([^/]+))?(/([^/]+))?/?',
        'index.php?id=$matches[2]&storyid=$matches[6]',
         'top'      
    );
}
add_action( 'init', 'rewrite_search_slug' );

Wordpress can do this by default. https://codex.wordpress.org/Using_Permalinks

You may consider using WordPress builtin permalinks option located in Settings tab. Set %category%/%postname%/ so that permalink should work as per your requirements. When posting new content, select a sub category and put post title the same you want to appear in your permalink. Hope it answers your question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM