ISHAN DOGRA ISHAN DOGRA - 3 months ago 15
Apache Configuration Question

.htaccess redirection for wordpress

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.

Answer

Try this rule as your very first rule:

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,NE,NC]

Leading slash / is not matched in .htaccess as it is per directory directive.