【问题标题】:Apache Fallback instead of add_rewrite_rule [closed]Apache Fallback而不是add_rewrite_rule [关闭]
【发布时间】:2014-06-05 10:00:32
【问题描述】:

我的要求是在 Wordpress 中为现有网站做 SEO 友好的 URL。

例如,

Current URL: http://localhost/test/?pid=19971
that is the page "test" is rendering the data from some custom plugin. 

My new SEO URL : http://localhost/brand/sub_category/product_name
Here, Brand, Sub_category and product_name is fetched from the pid..

我正在使用 functions.php 中的以下重写规则填充数据,

add_rewrite_rule(MY_DYNAMICALLY_POPULATED_URL.'$ page-test.php?brand='.$brand_name.'&sub='.$sub_category.'&pname='.$product_name.' [L]', 'top');

在此代码中,page-test.php 放置在根目录中,并通过传递 brand_namesub_categoryproductname 以获取 pid 从该文件呈现数据.因此,基于 pid 呈现每个产品页面。

这段代码对我来说很好用,当我自动保存数据时,数据会写入.htaccess,并且页面正在使用新的 SEO URL 呈现。

但是当我的客户需要它通过 Apache 中的 FALLBACK 而不是 add_rewrite_rule 时,由于某些负载平衡问题。

那么任何人都可以帮助我如何使用Fallback resource 做同样的事情。

【问题讨论】:

标签: php wordpress apache .htaccess fallback


【解决方案1】:

这解决了我的问题。

function my_query_vars($vars)
{
$my_vars = array( 'PARAMETERS' );
return array_merge($my_vars, $vars);
}
add_filter('query_vars', 'my_query_vars');


function my_rewrite_rules($rules)
{
global $wp_rewrite;
$my_page = 'PAGESLUG';
$my_rule = array( 'URL/?' => 'index.php?pagename=' . $my_page . '&school_type=$matches[1]' );
return array_merge($my_rule, $rules);
}
add_filter('page_rewrite_rules', 'my_rewrite_rules');

【讨论】:

    猜你喜欢
    • 2014-08-17
    • 2014-01-24
    • 2021-02-21
    • 2018-10-30
    • 1970-01-01
    • 2016-01-24
    • 2018-09-09
    • 2021-09-23
    • 1970-01-01
    相关资源
    最近更新 更多