【问题标题】:How to rewrite all non ssl request not containing a phrase?如何重写所有不包含短语的非 ssl 请求?
【发布时间】:2014-07-06 21:55:51
【问题描述】:

我有一个特殊的问题。我需要重写所有发往 http => https 的请求,此外,如果 URL 缺少 www,我想修复它,因此我也有一个重写规则。

现在,有一个例外,不应该重写。如果请求是针对 http://www.mydomain.com/api2/.../..

api2下的所有东西都不要改成https...

这是我当前的 .htaccess :

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]
# Start A2 Switcher Block
# Do not remove or modify this block! Added by PHP Switcher from cPanel to use an alterna$
<IfModule mod_suphp.c>
  AddHandler application/x-httpd-php-5.4.13 .php
</IfModule>
# End A2 Switcher Block

谁能帮忙?

【问题讨论】:

    标签: apache .htaccess mod-rewrite ssl url-rewriting


    【解决方案1】:

    你的代码是这样的:

    RewriteEngine on
    
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule !^api2/ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]
    
    RewriteCond %{HTTPS} off
    RewriteRule !^api2/ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]
    
    RewriteCond %{HTTPS} on
    RewriteRule ^api2/ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]
    
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^api2/ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]
    
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
    # Start A2 Switcher Block
    # Do not remove or modify this block! Added by PHP Switcher from cPanel to use an alterna$
    <IfModule mod_suphp.c>
      AddHandler application/x-httpd-php-5.4.13 .php
    </IfModule>
    # End A2 Switcher Block
    

    【讨论】:

    • 完美,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2019-08-06
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 2023-03-29
    相关资源
    最近更新 更多