简体   繁体   English

wordpress的.htaccess重定向

[英].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 ). 1.)当用户立即点击登录时,他将访问www.mysite.lu/en/wp-login.php或www.mysite.lu/fr/wp-login.php(WPML多语言)。 For all these types of URL its showing 404 page. 对于所有这些类型的URL,它显示404页面。 So we thought we can remove language from URL using .htaccess redirection method. 所以我们认为我们可以使用.htaccess重定向方法从URL中删除语言。 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. 使用上面的代码我们的登录URL工作正常。

2.) But our registration URL is 2.)但我们的注册网址是

   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. 我们不想重定向注册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. 请告诉我们做错了什么。

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. 在.htaccess中,前导斜杠/不匹配,因为它是每个目录指令。

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: 根据我的评论和更清晰的阅读使用这个,所以你不会受到RedirectMatch无法看到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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM