Reputation: 133
Due to bug in our theme, We are trying to achieve these tasks
1.) when user click on login right now he is going to www.mysite.lu/en/wp-login.php or www.mysite.lu/fr/wp-login.php ( WPML multilingual ). For all these types of URL its showing 404 page. So we thought we can remove language from URL using .htaccess redirection method. So we are using following code
Redirect /en/wp-login.php /wp-login.php?redirect_to=http://mysite.lu/en/my-account
Redirect /fr/wp-login.php /wp-login.php?redirect_to=http://mysite.lu/fr/my-account/
Redirect /de/wp-login.php /wp-login.php?redirect_to=http://mysite.lu/de/my-account
using above code our login URL is working fine.
2.) But our registration URL is
http://mysite.lu/en/wp-login.php?action=register
So when we click on register link its also redirecting to
http://mysite.lu/de/my-account
which is incorrect. We dont want to redirect register URL.
For this we also tried below code
RewriteCond %{QUERY_STRING} !(^|&)action=register($|&) [NC]
RewriteRule /en/wp-login\.php$ /wp-login.php?redirect_to=http://mysite.lu/en/my-account [L,R=301]
But this is also not working. please tell what we are doing wrong.
Upvotes: 1
Views: 110
Reputation: 2890
Based in my comments and for clearer reading use this so you are not affected by RedirectMatch not being able to see past the query_string:
<If "! %{QUERY_STRING} =~ /^.+/"> # or ^action just for action
RedirectMatch ^/(en|fr|de)/wp-login.php$ /wp-login.php?redirect_to=http://mysite.lu/$1/my-account/
</If>
Upvotes: 1
Reputation: 784878
Try this rule as your very first rule:
RewriteCond %{QUERY_STRING} !(^|&)action=register($|&) [NC]
RewriteRule ^([a-z]{2})/wp-login\.php$ /wp-login.php?redirect_to=http://mysite.lu/$1/my-account [L,R=301,NE,NC]
Leading slash /
is not matched in .htaccess as it is per directory directive.
Upvotes: 2