Regex 将单个页面重定向到HTTPS,将其余页面重定向到HTTP

Regex 将单个页面重定向到HTTPS,将其余页面重定向到HTTP,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我试图将一个WordPress页面(/scheduling/)重定向到HTTPS,同时在所有其他页面上强制使用HTTP。关于这个主题有很多类似的帖子,但是我的特定用例由于某种原因不起作用。想法 .htaccess # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME}

我试图将一个WordPress页面(
/scheduling/
)重定向到HTTPS,同时在所有其他页面上强制使用HTTP。关于这个主题有很多类似的帖子,但是我的特定用例由于某种原因不起作用。想法

.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^scheduling/
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^scheduling/
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
重新启动发动机
重写cond%{HTTPS}!在…上
RewriteCond%{REQUEST_URI}^调度/
重写规则(.*)https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
在上重写cond%{HTTPS}
重写cond%{REQUEST_URI}^日程安排/
重写规则(.*)http://%{http_HOST}%{REQUEST_URI}[L,R=301]
无论何时请求
https
,上述操作都会正确地重定向所有其他要重定向到
http
的页面,但对
调度
页面根本不起任何作用

  • 在默认WP规则之前执行重定向
  • 使用
    REQUEST
    变量,而不是
    REQUEST\u URI
  • 您可以使用:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTPS} off
    RewriteCond %{THE_REQUEST} /scheduling [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    
    RewriteCond %{HTTPS} on
    RewriteCond %{THE_REQUEST} !/scheduling [NC]
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    
    RewriteRule ^index\.php$ - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    
    #开始WordPress
    重新启动发动机
    重写基/
    重写条件%{HTTPS}关闭
    RewriteCond%{THE_REQUEST}/scheduling[NC]
    重写规则^https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301,NE]
    在上重写cond%{HTTPS}
    重写cond%{THE_REQUEST}/调度[NC]
    重写规则^http://%{http_HOST}%{REQUEST_URI}[L,R=301,NE]
    重写规则^index\.php$-[L]
    重写cond%{REQUEST_FILENAME}-F
    重写cond%{REQUEST_FILENAME}-D
    重写规则/index.php[L]
    #结束WordPress
    
    谢谢您的帮助。快速提问:
    请求URI
    为什么在这种情况下不起作用?它不只是返回请求的子集吗?伙计,我需要改进我的ApacheFoo…因为执行其他规则后,
    REQUEST\uURI
    的值会发生变化,这与
    REQUEST
    的情况不同。