最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

url rewriting - Why wordpress rewrite my custom URL?

programmeradmin4浏览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

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

Share Improve this question edited Jul 27, 2020 at 9:47 bhoqs asked Jul 24, 2020 at 9:33 bhoqsbhoqs 12 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 0

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

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]

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;
}
发布评论

评论列表(0)

  1. 暂无评论