Change the option of “Language Switcher” to fix the http status 302 redirect

This blog is written in two languages, Japanese and English. I am using Language Switcher which generates the hreflang and the language switch in the site. However, this cause that my web server reports the HTTP Status 302 with any pages.

Problem

Problem was below.

  1. Sometimes, the browser redirects to the top page when access to the sitemap.xml.
  2. The web server always reports HTTP Status 302 Redirect against any pages, even though it exists.

I found this problem with the Google Search Console. It reported that the sitemap.xml was not found and received HTTP Status 302 error.

Check the HTTP Header

Check the HTTP header to confirm.

$ curl -I "https://en.techgaku.com/sitemap.xml"

It exported below.

HTTP/2 302 
date: Thu, 03 Dec 2020 13:51:27 GMT
server: Apache
expires: Thu, 19 Nov 1981 08:52:00 GMT
cache-control: no-store, no-cache, must-revalidate
pragma: no-cache
x-redirect-by: WordPress
location: https://en.techgaku.com/
content-type: text/html; charset=UTF-8
set-cookie: PHPSESSID=8287fcaf01f2073684a4550f516b7a1e; path=/
set-cookie: lsw_f96b482c_m=en; path=/
set-cookie: lsw_f96b482c_d=en; path=/

The HTTP Status 302 is actually reported.

How to resolve

I have try and error, finally I found that one of feature of the Language Switcher doesn’t work properly. My web server is not compatible with this feature, and this feature can be disabled.

  1. Click the “Languages” link in the Word Press Dashboard.
  2. Open the “Settings” tab.
  3. Turn off “
  4. Click “Save Settings” button.

Confirm the problem was fixed

Check the HTTP header.

$ curl -I https://en.techgaku.com/sitemap.xml

It exported below and I confirmed that the problem was fixed, the HTTP Status is now 200.

HTTP/2 200 
date: Thu, 03 Dec 2020 14:05:15 GMT
server: Apache
x-robots-tag: noindex
cache-control: max-age=0
expires: Thu, 03 Dec 2020 14:05:15 GMT
content-type: text/xml; charset=utf-8
set-cookie: lsw_f96b482c_m=en; path=/
set-cookie: lsw_f96b482c_d=en; path=/

 

Author Profile

Akira HayashiA professional developer specializing in macOS Apps, iOS Apps, SDKs and middleware development.
Representative of RK Kaihatsu. I am a professional developer specializing in macOS Apps, iOS Apps, SDKs and middleware development. I often use ObjC, Swift and C++. Based on development experience, I provide e-learning contents, technical books and technical guidance. I am also a technical seminar instructor, in-house training instructor, and administrative / local goverment staff training instructor.
Get the Latest News !
>Programming Tips From Software Engineer

Programming Tips From Software Engineer

Technical News, Documents and Tips.

CTR IMG