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 DevelopmentApache Web ServerWordPress
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]
This mostly works except for some weird behaviour and mixed test results. When I test with Google Chrome incognito mode, I type https://theaksesuar.com and first it just connects and shows some distorted version of our site. When I refresh the page then it redirects to https://www.theaksesuar.com and displays the page correctly.
Redirect Checker and most other redirect checkers reports 200 instead of 301: https://www.redirect-checker.org
https://theaksesuar.com 200 OK
HTTP Headers
>>> https://theaksesuar.com

> --------------------------------------------
> 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
https://redirectdetective.com/ reports 301 fine. I will be glad if anyone can help.
Best Regards,
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
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