使用 .htaccess 重定向 IP 的条件语句?
大家好,我正在托管自己的服务器,并且有两个 IP 地址(一个用于从内部网内部连接的人,一个用于从外部连接的人),并且我有两个动态 dns 重定向到这些 IP。我刚刚在基于 apache2 的服务器上安装/设置了 SSL,并尝试使用 .htaccess 强制用户使用 https。我使用这样的语句使其工作。
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$https://mywebsite.dyn.site/$1 [R,L]
问题是,由于我对同一网站有两个单独的域名,因此该语句会将所有流量重定向到一个特定的域。我想我要问的是是否有a.)一种方法来放置条件if语句来检查他们的ip,或者最好b.)一种方法来删除“mywebsite”的硬编码,并为无论用户输入什么。
任何帮助将不胜感激。
Hey guys, I am hosting my own server and have two ip addresses for it (one for people connecting from within intranet and one for people connecting from outside) and I have two dynamic dns's redirecting to these ip's. I have just installed/setup SSL on my apache2-based server, and am trying to use .htaccess to force users to use https. I got it working using a statement like
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$https://mywebsite.dyn.site/$1 [R,L]
The problem is that since I have two separate domain names for the same website, that statement will redirect all traffic to one specific domain. I guess what I'm asking is whether there is a.) a way to put a conditional if statement to check for their ip, or preferably b.) a way to remove the "mywebsite" from being hardcoded, and putting a variable for whatever the user enters.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我搜索了大约半个小时,然后在我发布到 SO 上后,我找到了答案......哈哈。对于任何尝试做类似事情的人来说,您所要做的就是使用网址变量,而不是对其进行硬编码。
我这样做的方法是将其添加到我的 .htaccess 中:
这样它只会接受输入的任何 url 并将其从 http 更改为 https
干杯
Well I searched for about half an hour, and then right after I posted on SO I found the answer...lol. For anyone who is trying to do a similar thing all you have to do is use a variable for the web address, instead of hard coding it.
The way I did it was by adding this to my .htaccess:
This way it simply will take any url entered and change it from http to https
Cheers