WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. kboyko
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

    In case someone is interested, here is my solution:

    301 Redirect for HTTPS traffic in WordPress via .htaccess

  3. bottleneck
    Member
    Posted 1 year ago #

    Just in case, make sure your code starts with

    RewriteEngine on

  4. kboyko
    Member
    Posted 1 year 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

Tags