What I'm trying to do it's pretty much simple, but it's not working and I don't know if it's a Wordpress rewrite or I'm just doing it wrong.
What I have is this url:
http://www.example.com/newsletter/?ut=token
And I want .htaccess
to write it as following:
http://www.example.com/newsletter/confirm/token
Same thing for this:
http://www.example.com/newsletter/?uc=token
Which should be rewritten as:
http://www.example.com/newsletter/delete/token
This is my actual .htaccess
:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^newsletter/confirm/(.+)/?$ index.php?page_id=4058&ut=$1 [L,NC]
RewriteRule ^newsletter/delete/(.+)/?$ index.php?page_id=4058&del=$1 [L,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
4058 is the id of newsletter page. I've also tried this:
RewriteRule ^newsletter/confirm/(.+)/?$ newsletter/?ut=$1 [L,NC]
RewriteRule ^newsletter/delete/(.+)/?$ newsletter/?del=$1 [L,NC]
But it still not working at all. With the first method it goes to newsletter page without query string ( so it gives an empty page ); with the second one it gives 404 Not found.
I've also tried using Wordpress's built-in function add_rewrite_rule
without success, this is what I've tried:
function customRewriteRules(){
add_rewrite_rule('^newsletter/confirm/(.+)/?', 'index.php?page_id=4058&ut=$matches[1]', 'top');
add_rewrite_rule('^newsletter/delete/(.+)/?', 'index.php?page_id=4058&del=$matches[1]', 'top');
}
add_action('init', 'customRewriteRules');
Could it be something related to a kind of rewrite priority for Wordpress's base rewrite conditions? Or am I just doing it bad?
add_rewrite_url()
should work butadd_rewrite_endpoint()
seems more appropiated for your case. Can you show to us the code you have tried?add_rewrite_url()
instead ofadd_rewrite_rule()
flush_rewrite_rules()
(do it only on plugin activation/deactivation hook)