排除某些网页被重定向到https

时间:2015-06-15 15:54:48

标签: wordpress .htaccess redirect https http-redirect

我在WordPress网站上使用以下规则:

  1. 将所有http网页重定向到https
  2. 将职业页面重定向到http

    <IfModule mod_rewrite.c>
    RewriteEngine On
    # Go to https if not on careers
    RewriteCond %{SERVER_PORT} 80 
    RewriteCond %{REQUEST_URI} !^/careers$ [NC]
    RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
    
    # Go to http if you are on careers
    RewriteCond %{SERVER_PORT} !80 
    RewriteCond %{REQUEST_URI} ^/careers$ [NC]
    RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R,L]
    </IfModule>
    
  3. https重定向工作正常;但是,职业页面不会重定向到http。知道为什么吗?

    这是wp-config.php

    中的内容
    define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
    define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
    

1 个答案:

答案 0 :(得分:2)

尝试使用THE_REQUEST代替REQUEST_URI

<IfModule mod_rewrite.c>
RewriteEngine On
# Go to https if not on careers
RewriteCond %{SERVER_PORT} =80 
RewriteCond %{THE_REQUEST} !/careers/[\s?] [NC]
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]

# Go to http if you are on careers
RewriteCond %{SERVER_PORT} !=80 
RewriteCond %{THE_REQUEST} /careers/[\s?] [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R,L]
</IfModule>

THE_REQUEST变量表示Apache从您的浏览器收到的原始请求,并且在执行某些重写规则后不会被覆盖。此变量的示例值为GET /index.php?id=123 HTTP/1.1

确保将这些规则置于WP默认规则之上。

相关问题