问题描述:I have a WordPress site with a custom page comparison that gets a string.

Now it takes:

mysite.com/phones/compare/?between=samsung-galaxy-note-3-vs-nokia-lumia-730

It needs to be like that:

mysite.com/phones/compare/samsung-galaxy-note-3-vs-nokia-lumia-730

I’ve tried adding code on my site’s .htaccess that didn’t worked for me and went to WordPress 404 page:

RewriteRule ^phones/compare/(.+?)/?$ phones/compare/?between=$1 [NC,L]

Also I need to redirect to the new search engine friendly URL too when user gets to mysite.com/phones/compare/?between= URL.

解决办法:

You are getting a 404 page because WordPress internally doesn’t understand how to handle the URL. So the solution you are looking for will be a combination of .htaccess (for the redirection) plus a rewrite rule so that WordPress can handle the URL

Add the following to functions.php

add_action( 'init', 'init_custom_rewrite' );

function init_custom_rewrite() {

        add_rewrite_rule(        
            '^phones/compare/([^/]*)/?',        
            'index.php?page_id=XXX&between=$matches[1]',        
            'top' );
}

Replace XXX with the page_id of compare page, flush the rewrite rules by re-saving your permalink structure. Now add a rule to .htaccess for the redirection and that should work.

EDIT

Add the following code to functions.php to access between query var in the page

add_filter('query_vars', 'my_query_vars', 10, 1);

function my_query_vars($vars) {
    $vars[] = 'between'; 
    return $vars;
}

And you can then access it using get_query_var("between")

本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。

最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。 若排除这种情况,可在对应资源底部留言,或联络我们。

对于会员专享、整站源码、程序插件、网站模板、网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。

如果您已经成功付款但是网站没有弹出成功提示,请联系站长提供付款信息为您处理

源码素材属于虚拟商品,具有可复制性,可传播性,一旦授予,不接受任何形式的退款、换货要求。请您在购买获取之前确认好 是您所需要的资源