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.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.a) Determine whether you require serving www or bare domain.
b) Delete other indexing data from Google.
c) Get your redirect working, so all HTTP + HTTPS requests land on one version of site - www or bare domain
sudo nmap -sV -p 22,25,587,80,443,993,995 theaksesuar.com
theaksesuar.com: Starting Nmap 7.91 ( https://nmap.org ) at 2021-05-15 08:56 CDT
theaksesuar.com: Nmap scan report for theaksesuar.com (160.153.138.163)
theaksesuar.com: Host is up (0.18s latency).
theaksesuar.com: rDNS record for 160.153.138.163: ip-160-153-138-163.ip.secureserver.net
theaksesuar.com:
theaksesuar.com: PORT STATE SERVICE VERSION
theaksesuar.com: 22/tcp open ssh OpenSSH 7.5 (protocol 2.0)
theaksesuar.com: 80/tcp open daap mt-daapd DAAP
theaksesuar.com: 443/tcp open ssl/http OpenResty web app server
theaksesuar.com:
theaksesuar.com: Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
theaksesuar.com: Nmap done: 1 IP address (1 host up) scanned in 19.21 seconds
RewriteEngine On
RewriteCond %{HTTP_HOST} ^theaksesuar\.com$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
HTTP/2 200
server: openresty
date: Mon, 17 May 2021 13:40:22 GMT
content-type: text/html; charset=UTF-8
content-length: 200874
accept-ranges: bytes
age: 433686
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=300
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
strict-transport-security: max-age=31536000; includeSubDomains
Altough Chrome and other browsers I tested see and honor the redirect, curl gets 200 reply. I guess this is also what happens with Googlebot. I almost forgot, it's also not possible to delete URL https://theakesuar.com from Google search Console, since it says it will delete all www, non-www, http and https versions. Not good :)Tolgas-MacBook-Pro:~ tolgainci$ curl -I http://theaksesuar.com
HTTP/1.1 301 Moved Permanently
Age: 0
Cache-Control: max-age=2592000
Content-Type: text/html; charset=iso-8859-1
Date: Tue, 18 May 2021 06:07:05 GMT
Expires: Thu, 17 Jun 2021 06:07:05 GMT
Location: https://www.theaksesuar.com/
Vary: User-Agent, Accept-Encoding
X-Backend: local
X-Cache: uncached
X-Cache-Hit: MISS
X-Cacheable: NO:HTTPS Redirect
Tolgas-MacBook-Pro:~ tolgainci$ curl -I http://www.theaksesuar.com
HTTP/1.1 301 Moved Permanently
Age: 0
Cache-Control: max-age=2592000
Content-Type: text/html; charset=iso-8859-1
Date: Tue, 18 May 2021 06:07:34 GMT
Expires: Thu, 17 Jun 2021 06:07:34 GMT
Location: https://www.theaksesuar.com/
Vary: User-Agent, Accept-Encoding
X-Backend: local
X-Cache: uncached
X-Cache-Hit: MISS
X-Cacheable: NO:HTTPS Redirect
Tolgas-MacBook-Pro:~ tolgainci$ curl -I https://theaksesuar.com
HTTP/2 301
server: openresty
date: Wed, 19 May 2021 14:29:45 GMT
content-type: text/html; charset=iso-8859-1
age: 0
cache-control: max-age=2592000
expires: Fri, 18 Jun 2021 14:29:45 GMT
location: https://www.theaksesuar.com/
vary: User-Agent, Accept-Encoding
x-backend: local
x-cache: uncached
x-cache-hit: MISS
x-cacheable: NO:HTTPS Redirect
strict-transport-security: max-age=31536000; includeSubDomains
Unfortunately I'm not sure how it got fixed. The server seems to be not caching now, and honored the 301. By the way SSH'ed into my server and used curl on the localhost and got the same server:openresty result. So indeed it was my server replying not some front end server, and also CDN is off in Godaddy panel. After my tests in SSH the problem was suddenly solved, probably coincedence.
And you're correct, something's broken, as your redirect is failing.
Suggestions...
1) Till you get this resolve, change your 301 to 302, as 301s cache in browsers forever, which can be impossible to resolve.
2) Use this command to debug your setup...
Open in new window
OKhttps://theaksesuar.com/
3) Running commands in #2 shows your redirect is failing.
4) Real fix.
a) Determine whether you require serving www or bare domain.
b) Delete other indexing data from Google.
c) Get your redirect working, so all HTTP + HTTPS requests land on one version of site - www or bare domain - makes no real difference, so long as you adhere... to the... Highlander Rule...
"There can be only one".
So all HTTP + HTTPS drive/redirect/terminate at exactly 1x URL.