0

I am new in wordpress
There may a mapping question in my website

I hope this SEO URL is work and get Post data:
http://domain/web/d-post/M00069/TomLi

If not using SEO URL(get action), it is work!
http://domain/web/d-post?d_id=M00069&d_name=TomLi
http://domain/web/d-post/?d_id=M00069&d_name=TomLi
http://domain/web?pagename=d-post&d_id=M00069&d_name=TomLi
http://domain/web/?pagename=d-post&d_id=M00069&d_name=TomLi

In this case
http://domain/web/d-post/M00069/TomLi
but why my page will redirect to:
http://domain/web/d-post/

Should I set or change something that can make my URL work?
Thanks a lot

In .htaccess

#
RewriteEngine On
RewriteBase /web/
RewriteRule ^d-post/([A-Z0-9]+)/(.*)/$ ?pagename=d-post&d_id=$1&d_name=$2 [L]
#

Without using wp & run at localhost it is work If not using wordpress

3 Answers 3

0

If i clearly understood you want to change permalink. you can set any type of permalink in admin menu > settings >permalinks.

2
  • You can't set this kind of search URL in the permalinks option page.
    – fuxia
    Commented Jul 24, 2020 at 15:31
  • wordpress permalinks setting not suitable for case, I use plugin to make this page(d-search)
    – bhoqs
    Commented Jul 25, 2020 at 6:11
0

Try by this.

function myff() {
    global $wp_rewrite;
    
    if ( !isset( $wp_rewrite ) || !is_object( $wp_rewrite ) || !$wp_rewrite->using_permalinks() )
        return;
    if ( is_search() && !is_admin() && strpos( $_SERVER['REQUEST_URI'], "/search/") === false && ! empty( $_GET['s'] ) ) {
        wp_redirect( site_url() . "/search/" . urlencode( get_query_var( 's' ) ) );
        exit;
    }   
}
 
add_action( 'template_redirect', 'myff' );

Or through .htaccess

   RewriteCond %{QUERY_STRING} \\?s=([^&]+) [NC]
RewriteRule ^$ /search/%1/? [NC,R,L]
1
  • thanks, but it looks not working
    – bhoqs
    Commented Jul 27, 2020 at 9:43
0

Oh I find I should add some filter

add_filter('query_vars','d_search_1');
function d_search_1($vars) {
    array_push($vars, 'd_id');
    return $vars;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.