I’m having a little Problem with mod_rewrite in combination with wordpress 🙁
This is my 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
So i get links like “www.mysite.de/articlename”
Now i wanted to create a page, where i can see the userinformations in the frontend.
So i want a link like “www.mysite.de/users/profile/admin” to be rewritten to “www.mysite.de/users/?user=admin”
I searched for more than 5 hours now, but dont get it working 🙁
This is what i tried
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]
Btw: /users is a site i created before via the WordPress Backend. If i use pagename=users i just get redirected to http://www.mysite.de/users 🙁
Any suggestions? Thanks for your help 🙂
Edit: Btw I tried the wp_directions from wordpress it self as well. No success
I added this to the 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;
}
There’s an error in your rule:
The parentheses needs to enclose the
.*: