简体   繁体   中英

WordPress redirect full site to HTTPS and then add redirect rule for one page to HTTP

After a long R&D process, I am here with an unresolved issue of WordPress redirection. None of the available resources helped me really.

What I need is -

I have successfully redirected my entire WP site and admin to HTTPS.

Now, I need one specific page to redirect to HTTP only. Because I will be using iframe on that page to load external sites for preview.

My requested url should be like this -

http://example.com/live-preview/?product_id=(number like 1,2,3 etc)

I want the above url(s) to load without HTTPS.

My present htaccess file is this -

# BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R=301,L]

RewriteBase /

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>


# END WordPress

So anything with (/live-preview/) should be on HTTP only. Please help me how I will be able to do this.

Thank you so much. -Amit

After a long investment of time and many researches, I manage to fix this issue with my code. I am sharing this for public interest.

This is the working htaccess code -

RewriteCond %{HTTPS} !on
RewriteCond %{QUERY_STRING} !^product_id=(.*)$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]


RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} ^product_id=(.*)$
RewriteRule ^(.*)$ http://%{SERVER_NAME}/$1 [R=301,L]

So I have to use {QUERY_STRING} and use 2 conditions with 301 permanent redirection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM