0

我在将 mod_rewrite 与 wordpress 结合使用时遇到了一点问题:(

这是我的 htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

所以我得到像“www.mysite.de/articlename”这样的链接

现在我想创建一个页面,我可以在前端看到用户信息。所以我希望将“www.mysite.de/users/profile/admin”之类的链接重写为“www.mysite.de/users/?user=admin”

我现在搜索了 5 个多小时,但没有得到它的工作:(

这是我试过的

RewriteEngine On
RewriteBase /
RewriteRule ^users/profile/(.)*$ users/?user=$1 [L]
# RewriteRule ^users/profile/(.)*$ index.php/pagename=users&user=$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

顺便说一句:/users 是我之前通过 Wordpress 后端创建的网站。如果我使用 pagename=users 我只是被重定向到 www.mysite.de/users :(

有什么建议么?谢谢你的帮助 :)

编辑:顺便说一句,我也尝试了 wordpress 中的 wp_directions 。没有成功我将它添加到functions.php

add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
add_filter( 'query_vars','my_insert_query_vars' );
add_action( 'wp_loaded','my_flush_rules' );

// flush_rules() if our rules are not yet included
function my_flush_rules(){
    $rules = get_option( 'rewrite_rules' );

    if ( ! isset( $rules['(users)/(\d*)$'] ) ) {
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
    }
}

// Adding a new rule
function my_insert_rewrite_rules( $rules )
{
    $newrules = array();
    $newrules['(users)/(\d*)$'] = 'index.php?pagename=$matches[1]&id=$matches[2]';
    return $newrules + $rules;
}

// Adding the id var so that WP recognizes it
function my_insert_query_vars( $vars )
{
    array_push($vars, 'id');
    return $vars;
}
4

1 回答 1

0

你的规则有错误:

RewriteRule ^users/profile/(.)*$ users/?user=$1 [L]

括号需要括起来.*

RewriteRule ^users/profile/(.*)$ users/?user=$1 [L]
于 2012-07-18T21:50:04.647 回答