简体   繁体   English

.htaccess在WordPress多站点内重定向

[英].htaccess redirect within WordPress Multi-site

Using a standard WordPress setup I had the following in htaccess... 使用标准的WordPress设置,我在htaccess中有以下内容...

RewriteCond %{QUERY_STRING} ^registration=disabled$ [NC]
RewriteRule ^wp-login.php$ http://www.mysite.com/register [L,R=301,NC]

Which successfully redirected any calls to wp-login.php?registreation=disabled to http://www.mysite.com/register 哪个成功将任何呼叫重定向到wp-login.php?registreation = disabled到http://www.mysite.com/register

I have now moved over to multi-site so need the redirect to send the user to whatever site within the network they are browsing, how can i do this? 我现在已移至多站点,因此需要重定向以将用户发送到他们正在浏览的网络内的任何站点,我该怎么做?

UPDATE 更新

To clarify, as I am now using multi-site I could now be faced with different sub-domains and addresses such as 需要澄清的是,由于我现在使用的是多站点,因此现在可能会遇到不同的子域和地址,例如

www.mydomain1.com/testsite www.mydomain2.com/example www.mydomain3.com/various www.mydomain1.com/testsite www.mydomain2.com/example www.mydomain3.com/various

I am looking for a one size fits all htaccess command that will redirect 我正在寻找一个适合所有htaccess命令的大小将重定向的命令

You can just remove the domain from your RewriteRule : 您可以从RewriteRule删除域:

RewriteCond %{QUERY_STRING} ^registration=disabled$ [NC]
RewriteRule ^wp-login.php$ /register [L,R=301,NC]

Tested here and it seems to work, although it doesn't trim off the query string (but then, neither does the original). 在这里进行了测试,尽管它没有修剪掉查询字符串(但随后的原始字符串也没有),但似乎可以正常工作。 If you want the query string removed, make the RewriteRule the following: 如果要删除查询字符串,请使RewriteRule成为以下形式:

RewriteRule ^wp-login.php$ /register? [L,R=301,NC]

Edit: I can't test this on a real system at the moment, and unfortunately the link I provided doesn't support ${HTTP_HOST} , however you could add another condition which matches any http_host, and use a back-reference in the RewriteRule to put in that value: 编辑:目前,我无法在实际系统上对此进行测试,很遗憾,我提供的链接不支持${HTTP_HOST} ,但是您可以添加与任何 http_host匹配的另一个条件,并在其中使用反向引用。 RewriteRule放入该值:

RewriteCond %{QUERY_STRING} ^registration=disabled$ [NC]
RewriteCond %{HTTP_HOST} (.*)
RewriteRule ^wp-login.php$ http://%1/register? [L,R=301,NC]

As mentioned, I can't currently test this, but in theory it should work :) 如上所述,我目前无法对此进行测试,但从理论上讲,它应该可以工作:)

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

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