301 Redirect from HTTPS fails in strange way (4 posts)

  1. kboyko
    Posted 2 years ago #

    I came across strange issue with 301 redirect. I have a need of redirecting all HTTPS traffic to HTTP except a few pages (let's say it has URL /sample-page/). So I added a rewrite rule to .htaccess like this:

    RewriteCond %{SERVER_PORT} ^443$
    RewriteCond %{REQUEST_URI} !^\/sample-page
    RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]

    And for some reason https://mydomain.com/sample-page/ is redirected to http://mydomain.com/ - thought it has to be left as is. Every other HTTPS URL is redirected to its HTTP version as expected.

    I've tried this on clean WordPress installation with just permalinks turned on. This is true for every page, not just some specific.

    Also if WordPress rewrite rules are removed the redirect works fine. So it has to have something to do with WordPress. Does anyone know what it could be?

  2. kboyko
    Posted 2 years ago #

    In case someone is interested, here is my solution:

    301 Redirect for HTTPS traffic in WordPress via .htaccess

  3. bottleneck
    Posted 2 years ago #

    Just in case, make sure your code starts with

    RewriteEngine on

  4. kboyko
    Posted 2 years ago #

    Of course, it was just not the thing I wanted to highlight

Topic Closed

This topic has been closed to new replies.

About this Topic