I have been receiving lots of canonical error messages from Google Search Console. Most of the time, the referring pages are my own pages and the urls are correct in the referring page.
Google is indicating that the errors are destination urls without a trailing slash. I.e, example.com/mypage
vs example.com/mypage/
However, my permalink structure in WordPress is set to end all urls with a trailing slash. The user declared canonicals are also using trailing slashes according to the page source and Google.
I think the problem is with my htaccess file and a WordPress plugin that has enabled https rewrites. My current htaccess rewrite rule is below.
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
I'm not a regular expression or htaccess expert, but if I want my permalinks to all end with a slash shouldn't this be:
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1/ [R=301,L]
I.e., shouldn't there be a "/" after the $1?
Edit
If I type in http:example.com/mypage
in the address bar, it still redirects to https://example.com/mypage/
.
Plugin Rewrite section (comes first in htaccess file):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
Wordpress Rewrite section (comes later in htaccess file):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Note: After looking at my network tab (as MrWhite suggested) I see only one 301 redirect (not two). I.e., http://example.com/mypage
is redirected to https://example.com/mypage
without the trailing slash. Additionally, if I use https://example.com/mypage
it redirects to https://example.com/mypage
without the trailing slash as well even though the url is identical.
Mr White, you are correct, I am using Cloudflare and my SSL is set to strict on Cloudflare.
Request/Reponse Headers:
GET /mypage HTTP/2
Host: example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
...
Upgrade-Insecure-Requests: 1
...
Pragma: no-cache
Cache-Control: no-cache
TE: trailers
HTTP/2 301 Moved Permanently
...
location: https://example/mypage/
strict-transport-security: max-age=63072000; includeSubDomains;preload
...
x-redirect-by: WordPress
...
server: cloudflare
...
X-Firefox-Spdy: h2
/mypage
to/mypage/
triggered by a rule in.htaccess
or by WordPress? Check the network traffic to make sure there is not a (lengthy/incorrect) redirect chain. (Although if the redirect to append the trailing is performed by WP then you would see 2 redirects... the first to HTTPS and the second to append the trailing slash. But this is not necessarily wrong.)https://example.com/mypage
it redirects tohttps://example.com/mypage
without the trailing slash as well even though the url is identical." - Are you actually seeing an external 3xx redirect? What is the HTTP status? What are the HTTP response headers on these requests?