我在使用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;
}
答案 0 :(得分:0)
您的规则中存在错误:
RewriteRule ^users/profile/(.)*$ users/?user=$1 [L]
括号需要括起.*
:
RewriteRule ^users/profile/(.*)$ users/?user=$1 [L]