htaccess的限制子域由IP - 字preSS多站点 [英] .htaccess restrict subdomain by IP - Wordpress Multisite

查看:108
本文介绍了htaccess的限制子域由IP - 字preSS多站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将流量重定向远离子域安装的话语preSS多站点的除非的它是从一个特定的IP地址/范围的到来,也不会影响根域的流量。这可能吗?

I'd like to redirect traffic away from a subdomain install of Wordpress Multisite unless it's coming from a specific IP address/range, and without affecting the root domain traffic. Is this possible?

在概念上,我一直在想是这样的:

Conceptually, I've been thinking something like this:

# IF we're dealing with the subdomain
RewriteCond %{HTTP_HOST} subdomain\.example\.com [NC]

# AND the user is NOT from our allowed IP
RewriteCond %{REMOTE_ADDR} !111\.222\.333\.444

# THEN redirect them to the root domain
RewriteRule ^(.*)$ http://example.com/$1 [L,R=302]

在换句话说,限制从一个不从定义的IP地址发起的所有流量访问子域。我从字面上刚刚学会正则表达式和.htaccess对于这一点,所以道歉提前任何东西那是错得离谱。

In other words, restrict access to the subdomain from all traffic that doesn't originate from a defined IP address. I've literally just learned regex and .htaccess for this, so apologies in advance for anything that's glaringly wrong.

的原因,我不能与目录中的特定的.htaccess这样做这是我的工作有一个子域安装Word preSS多地点的,因此没有目录。这一切都在URL中。

The reason I'm not doing this with directory specific .htaccess is that I'm working with a subdomain install of Wordpress Multisite, so there are no directories. It's all in the URL.

一些可能出现的并发症是来自字preSS本身:

Some possible complications that come from Wordpress itself:

  1. 理想地,这些规则应该以这样一种方式,他们不会被覆盖每次永久链接缓存刷新WP时间加入。
  2. 我不知道是什么的RewriteBase / 的计算结果为,或者它是如何影响的URI(如果这是正确的首字母缩写)在我的文件中。
  1. Ideally these rules should be added in such a way that they aren't overwritten every time the permalink cache is refreshed in WP.
  2. I'm not sure what RewriteBase / evaluates to, or how it's affecting URIs (if that's the correct acronym) in my file.

编辑:

每@Prix反馈,下面是完整的.htaccess文件我正在使用:

Per @Prix feedback, here is the complete .htaccess file I'm working with:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} subdomain\.example\.com [NC]
RewriteCond %{REMOTE_ADDR} !111\.222\.333\.444
RewriteRule ^(.*)$ http://example.com/$1 [L,R=302]

RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>

# END WordPress

这是道preSS'多站点的默认规则,用我自己的添加后的RewriteBase / 立即列入。我纳入@ hjpotter92的建议。

This is Wordpress' Multisite default rules, with my own additions included immediately after RewriteBase /. I incorporated @hjpotter92's suggestion.

期望影响它重定向的所有的流量subdomain.example.com到example.com,除非的它是从一个特定的IP地址来了。这是谁的本质用他们的话preSS多地点的部分作为公司外部网的客户端。

The desired affect it to redirect all traffic from subdomain.example.com to example.com, unless it's coming from a specific IP address. This is for a client who's essentially using part of their Wordpress Multisite as a company extranet.

推荐答案

规则看起来不错,是的,我唯一会改变的是这样的:

The rule looks fine yes, the only thing I would change is this:

RewriteRule ^(.*)$ http://example.com/$1 [L,R=302]

进入这个

RewriteRule ^ http://example.com/ [L,R=302] 

由于您没有从给定的子域的份额要在重定向404一边同的DocumentRoot ,然后是的,它应该工作,因为我已经测试它自己

As you don't want a 404 on the redirect aside from that given the subdomain share the same DocumentRoot, then yes, it should work as I have tested it myself.

我希望在这一行:

RewriteCond %{HTTP_HOST} subdomain\.example\.com [NC] 

你不增加噪音,它像的http:// 或以外的任何限定域名,例如内部网\ .mydomainname \ .COM 没有斜线,没有HTTP等。

You're not adding noise to it like http:// or anything other than the qualified domain name, such as for example intranet\.mydomainname\.com no slash, no http, etc.

这篇关于htaccess的限制子域由IP - 字preSS多站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆