如何在htaccess中强制http://?

Sta*_*bie 8 apache .htaccess mod-rewrite

我目前在我的htaccess文件中有这个在我登录的所有页面上强制https并注册页面:

# Force https://
<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTPS} off
    RewriteCond $1 ^(sign-in|sign-up) [NC]
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

我想在页面未登录或注册时强制http.我怎么做?

编辑1:

我实际上需要做以下事情:

  1. 强制https://页面sign-upsign-in
  2. http://页面强制不在sign-upsign-in
  3. 去掉 www
  4. 去掉 index.php

我的.htaccess的相关部分有这个:

#
# Force https:// or http://
#
<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTPS} off
    RewriteCond $1 ^(sign-in|sign-up) [NC]
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    #RewriteCond %{HTTPS} on
    #RewriteCond $1 !^(sign-in|sign-up) [NC]
    #RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    #RewriteCond %{HTTPS} on
    #RewriteCond %{REQUEST_URI} !^/(sign-in|sign-up)(/|$) [NC]
    #RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

#
# Supress "www" at the beginning of URLs. Source: HTML5 Boilerplate
#
<IfModule mod_rewrite.c>
    RewriteEngine On

    #RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>

#
# Supress "index.php"
#
<IfModule mod_rewrite.c>
    RewriteEngine On

    # Removes index.php from ExpressionEngine URLs
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

小智 0

我个人还没有实现过这种解决方案(我倾向于使用 PHP 解决方案,如上面的解决方案,因为它很简单),但以下至少可能是一个好的开始。

RewriteEngine on

# Check for POST Submission
RewriteCond %{REQUEST_METHOD} !^POST$

# Forcing HTTPS
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{SERVER_PORT} 80
# Pages to Apply
RewriteCond %{REQUEST_URI} ^something_secure [OR]
RewriteCond %{REQUEST_URI} ^something_else_secure
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

# Forcing HTTP
RewriteCond %{HTTPS} =on [OR]
RewriteCond %{SERVER_PORT} 443
# Pages to Apply
RewriteCond %{REQUEST_URI} ^something_public [OR]
RewriteCond %{REQUEST_URI} ^something_else_public
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Run Code Online (Sandbox Code Playgroud)