English 中文(简体)
将网络服务器上的所有流量都转到 https 上?
原标题:How can I add an exception to the mod_rewrite which redirects all traffic on a webserver to https?
  • 时间:2012-05-24 15:34:42
  •  标签:
  • https
  • apache

我目前在网络上使用以下脚本:

    #########################################
    #### BEGIN EDIT FOR MOD_REWRITE ####
    #### This is intended to force HTTPS ####
    #### for all inbound HTTP requests ####

    ####
    # This module (mod_rewrite) simply tells Apache2 that all connections to
    # port 80 need to go to port 443 . SSL . No exceptions
    ####

    
    LoadModule rewrite_module modules/mod_rewrite.so
    
    
    RewriteEngine on

    ####
    # The line below sets the rewrite condition for mod_rewrite.so.
    # That is, if the server port does not equal 443, then this condition is true
    ####

    RewriteCond %{HTTPS} !=on
    #ReWriteCond %{SERVER_PORT} !^443$

    ####
    # The line below is the rule, it states that if above condition is true,
    # and the request can be any url, then redirect everything to https:// plus
    # the original url that was requested.
    ####

    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
    

    #### END EDIT FOR MOD_REWRITE ####
    #######################################

该脚本被添加到我的 httpd.conf 文件中, 它运行在 LAMP 堆放的 CentOS 服务器上。 它完全可以做我需要它做的, 也就是将所有流量都转到服务器上的任何网站到 https 。

然而,我想对服务器上一个不需要使用 https 的站点做一个例外。 我该怎么配置这个例外?

我为一个基本问题道歉,因为我不是贸易开发商。

提前感谢!

最佳回答

找到了。 不得不添加以下一行作为重写集 :

RewriteCond  %{HTTP_HOST}  !^www.example.com*
问题回答

试这个

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}




相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签