troubleshooting Question

Why is my .htaccess redirect returning 200 instead of 301 during testing?

Avatar of Tolga Inci
Tolga InciFlag for Turkey asked on
Web DevelopmentWordPressApache Web Server
11 Comments1 Solution18 ViewsLast Modified:
We have a Wordpress site, and it was changed from non-www to www several times due to some problems. The main issue is that Google indexed both versions which is not good. Finally we settled for www, and want to make sure non-www is not directly accesible from now on. Here is the code we used in .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Open in new window

This mostly works except for some weird behaviour and mixed test results. When I test with Google Chrome incognito mode, I type and first it just connects and shows some distorted version of our site. When I refresh the page then it redirects to and displays the page correctly.
Redirect Checker and most other redirect checkers reports 200 instead of 301: 200 OK
HTTP Headers

> --------------------------------------------
> 200 OK
> --------------------------------------------

Status: 200 OK
Code:   200
Server: openresty
Date:   Fri, 14 May 2021 07:50:51 GMT
Content-Type:   text/html; charset=UTF-8
Connection: close
Accept-Ranges:  bytes
Age:    153515
Cache-Control:  max-age=2592000
Content-Security-Policy:    upgrade-insecure-requests
Expires:    Fri, 11 Jun 2021 13:12:16 GMT
Last-Modified:  Wed, 12 May 2021 09:57:00 GMT
Strict-Transport-Security:  max-age=31536000; includeSubDomains
Vary:   Accept-Encoding, User-Agent
X-Backend:  local
X-Cache:    cached
X-Cache-Hit:    HIT
X-Cacheable:    YES
X-Content-Type-Options: nosniff
X-Xss-Protection:   1; mode=block

Open in new window reports 301 fine. I will be glad if anyone can help.
Best Regards,
David Favor
Fractional CTO
Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros