apache rewrite:强制使用https和服务器名称,而不是IP [英] apache rewrite: force https and name of server, not IP

查看:40
本文介绍了apache rewrite:强制使用https和服务器名称,而不是IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的Apache总是强迫人们使用https并映射基于IP的查找以转发到服务器名称.以下设置(位于httpd.conf文件中)负责将http重定向到https:

I want my apache to always force people to use https and to map IP based look ups to be forwarded to the server name. The following settings (in httpd.conf file) take care of the http to https redirect:

<Location />
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://my_server.example.com%{REQUEST_URI}
</Location>

但是现在我还希望,如果人们输入192.168.1.2,他们将被重定向到my_server.example.com. 总结一下:

But now I also want that if people type 192.168.1.2 they get redirected to my_server.example.com. To sum up:

http://192.168.1.2/someurl -> https://my_server.example.com/someurl

我尝试了几种方法,但是要么设置被忽略,要么最终进入重定向循环. 有什么提示吗?

I've tried several things but either my settings get ignored or I end up in a redirect loop. any hints?

推荐答案

我想出了以下解决方案:

I figured out the following solution:

<Location />
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^my_server\.example\.com [NC]
    RewriteRule (.*) https://my_server.example.com%{REQUEST_URI} [R=301,L]
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://my_server.example.com%{REQUEST_URI}
</Location>

它完全满足我的需求.

这篇关于apache rewrite:强制使用https和服务器名称,而不是IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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