Redirect Wordpress将url重写为插件文件

Redirect Wordpress将url重写为插件文件,redirect,url-rewriting,wordpress,Redirect,Url Rewriting,Wordpress,我无法重定向到插件页面 我找不到页面 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');

我无法重定向到插件页面

我找不到页面

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

我厌倦了修改重新连接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_类型名称(如类别、自定义post_类型)
如果我想重定向到未注册分类法、标记、帖子类型的页面,该怎么办?

因为我使用的标记不是任何类型(例如帖子、页面、类别、作者、搜索)。。 而且,wordpress上可能没有启用漂亮的URL。我无法使用添加\重写\规则()

如果我需要使用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 );        
}   
    }
}
}
函数mod_rewrite_规则($rules){
$home\u root=parse\u url(home\u url());
if(isset($home\u root['path']))
$home_root=trailingslashit($home_root['path']);
其他的
$home_root='/';
$rules=array();
$rules[]=“”;
$rules[]=“重写引擎打开”;
$rules[]=“RewriteBase$home\u root”;
$rules[]=“RewriteRule^oauth/facebook/?$wp content/plugins/my_plugin/file.php?[L]\n”;//防止对index.php进行-f检查。
$rules[]=“\n”;
$home\u path=获取home\u path();
$htaccess_file=$home_path.'.htaccess';
//如果文件不存在,请检查对目录的写访问权限,以及我们是否有一些规则。
//否则,请检查文件的写访问权限。
如果(文件存在($htaccess\u file)&&is\u可写($home\u path)&&is\u可写($htaccess\u file)){
插入带有_标记的_($htaccess_文件,$优惠券,$rules);
}   
}
}
}