0

我无法重定向到插件页面..

我找不到页面..

add_action( 'init', 'myplugin_rewrite_internal' );
function myplugin_rewrite_internal() {
     global $wp_rewrite;

    add_rewrite_rule('oauth/facebook/$', plugins_url('/oauth/facebook/index.php' 
    ,dirname(__FILE__)), 'top');
    $wp_rewrite->flush_rules(true);  // This should really be done in a plugin activation
}

我打电话的网址

www.example.com/oauth/facebook/index.php

我厌倦了 mod_rewite_url 仍然找不到页面

 add_action('generate_rewrite_rules', array(&$this, 'generate_rewrite_rules'));
 add_filter('mod_rewrite_rules', array(&$this, 'mod_rewrite_rules'));

function generate_rewrite_rules() {
    global $wp_rewrite;
    $non_wp_rules = array(
        'oauth/facebook/?$plugin_name' => plugins_url('/oauth/facebook/index.php' 
    ,dirname(__FILE__)),

    );

    $wp_rewrite->non_wp_rules = $non_wp_rules + $wp_rewrite->non_wp_rules;
}

function mod_rewrite_rules($rules) {
    $rules = preg_replace('/^(RewriteRule ^.*+/?$)plugin_name (/)(.*) ([QSA,L])$/im', '1 3 [R=301,L]', $rules);
    return $rules;
}

请纠正我..我已经尝试了很多次.. add_rewrite_url 仅适用于已注册的分类、标签、post_types 名称,如类别、自定义 post_type 如果我想重定向到未注册分类、标签、post_types 的页面怎么办?

4

1 回答 1

0

由于我没有使用任何类型的标签(例如帖子、页面、类别、作者、搜索).. 并且漂亮的 url 可能无法在 wordpress 上启用。我不能使用 add_rewrite_rule();

如果我需要使用 add_rewrite_rule() 则必须启用漂亮的 url。

因此,重写 url 的唯一方法是编辑 htaccess 文件。所以这就是功能

在插件激活时需要调用它来将规则保存到 htaccess

function mod_rewrite_rules($rules) {

$home_root = parse_url(home_url());
if ( isset( $home_root['path'] ) )
    $home_root = trailingslashit($home_root['path']);
else
    $home_root = '/';

$rules = array();
$rules[] =  "<IfModule mod_rewrite.c>";
$rules[] =  "   RewriteEngine On";
$rules[] =  "   RewriteBase $home_root";    
    $rules[] =   "  RewriteRule ^oauth/facebook/?$  wp-content/plugins/my_plugin/file.php? [L]\n"; // Prevent -f checks on index.php.
$rules[] = "</IfModule>\n"; 
$home_path = get_home_path();
$htaccess_file = $home_path.'.htaccess';

// If the file doesn't already exist check for write access to the directory and whether we have some rules.
// else check for write access to the file.

if (file_exists($htaccess_file) && is_writable($home_path) &&  is_writable($htaccess_file)) {
        insert_with_markers( $htaccess_file, 'Coupon', $rules );        
}   
    }
}
}
于 2013-07-21T14:17:40.163 回答