【发布时间】:2013-10-29 16:05:30
【问题描述】:
我在使用 wp_rewrite.. 时遇到问题。似乎无法正常工作..
我需要更改此网址:
/eduedu/wp-content/plugins/workwork/admin/templates/tcpdf/samp/flash.php
到
/eduedu/generator
function create_rewrite_rules() {
add_rewrite_rule($wordpress_root.'/generator/?$', 'wp-content/plugins/workwork/admin/templates/tcpdf/samp/flash.php');
}
function flush_the_rewrite_rules () {
flush_rewrite_rules;
}
add_action('init', 'flush_the_rewrite_rules');
add_filter('generate_rewrite_rules', 'create_rewrite_rules');
【问题讨论】:
-
如果
$wordpress_root是在函数外部定义的(很可能是这样),你需要在函数内部使用之前添加global $wordpress_root -
另外,“generate_rewrite_rules”是一个action,而不是一个filter。 reference
-
嗨,你能举个例子吗?我在我的 wordpress 的根文件夹上添加了 .htaccess 并且它可以工作,但是如果将 htaccess 添加到 plugins 文件夹中它就不起作用..
-
.htaccess 文件需要在您的 wordpress 目录的根目录中,而不是在内部目录中。