重定向特定的Word preSS页面到HTTPS [英] Redirect specific WordPress pages to HTTPS

查看:368
本文介绍了重定向特定的Word preSS页面到HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字preSS网站,并希望重定向特定页面到HTTPS。具体而言,我想 http://www.mydomain.com/?page_id=4 被重定向到 https://www.mydomain.com /?PAGE_ID = 4 。我采取的方法是添加以下为.htaccess:

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^ HTTP://www.mydomain.com/ PAGE_ID = 4 [NC]
重写规则^(。*)$ https://www.mydomain.com/?page_id=4/$1 [R = 301,L]
 

但是,当我浏览网页,它不会重定向。有什么想法?

解决方案

唉... %{HTTP_HOST} 变量将被解析为只在一个域名您例如,它会只是 www.mydomain.com 。你需要不止于此:

 选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
#强制安全本页面版本
的RewriteCond%{QUERY_STRING} ^ PAGE_ID =(\ d +)[NC]
的RewriteCond%{HTTPS} =关闭
的RewriteCond%{HTTP_HOST} = www.mydomain.com
重写规则^(。*)$ https://www.mydomain.com/$1?page_id=%1 [R = 301,L]
 

  1. 您必须通过3的RewriteCond报表中单独比较查询字符串,协议和可选域名。

  2. 我已删除 / $ 1 的目标URL - 这是没有意义的。所有的这是什么规则,应该做的是重定向到安全的版本,这和只有这一个特定的URL。

  3. 我不知道这是真正需要这一行:的RewriteCond%{HTTP_HOST} = www.mydomain.com 。它应该能正常运行离不开它了。

  4. 请确保您放在适当的位置这一规则 - 它应该放在字preSS重写规则


更新: 备选:

 选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
#强制安全本页面版本
的RewriteCond%{QUERY_STRING} ^ PAGE_ID =(\ d +)(。*)[NC]
的RewriteCond%{HTTPS} =关闭
的RewriteCond%{HTTP_HOST} = www.mydomain.com
重写规则^(。*)$ https://www.mydomain.com/$1 [QSA,R = 301,L]
 

I have a WordPress site and want to redirect specific pages to HTTPS. Specifically, I want http://www.mydomain.com/?page_id=4 to be redirected to https://www.mydomain.com/?page_id=4. The approach that I have taken is to add the following to .htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^http://www.mydomain.com/?page_id=4 [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/?page_id=4/$1 [R=301,L]

But when I navigate to the page, it does not redirect. Any thoughts?

解决方案

Well ... %{HTTP_HOST} variable will be resolved to a domain name only and in your example it will be just www.mydomain.com. You'll need more than that:

Options +FollowSymLinks -MultiViews
RewriteEngine on
# force secure version of this page
RewriteCond %{QUERY_STRING} ^page_id=(\d+) [NC]
RewriteCond %{HTTPS} =off
RewriteCond %{HTTP_HOST} =www.mydomain.com
RewriteRule ^(.*)$ https://www.mydomain.com/$1?page_id=%1 [R=301,L]

  1. You have to compare query string, protocol and optionally domain name separately via 3 RewriteCond statements.

  2. I have removed /$1 from target URL -- it makes no sense. All what this rule supposed to do is to redirect to secure version of this and only this one particular URL.

  3. I'm not sure that this line is really required: RewriteCond %{HTTP_HOST} =www.mydomain.com. It should work fine without it.

  4. Make sure that you put this rule in appropriate place -- it should be placed BEFORE WordPress rewrite rules.


UPDATE: Alternative:

Options +FollowSymLinks -MultiViews
RewriteEngine on
# force secure version of this page
RewriteCond %{QUERY_STRING} ^page_id=(\d+)(.*) [NC]
RewriteCond %{HTTPS} =off
RewriteCond %{HTTP_HOST} =www.mydomain.com
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [QSA,R=301,L]

这篇关于重定向特定的Word preSS页面到HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆