大网数据广告活动
网站运营与故障问答

Trailing slash, google search console and sitemap

· 52CE 我爱测

I force usage of trailing slash for all of my pages under https://example.com , however the main domain remains without it - from what I've read it's OK to do so, but I'm not sure how does Google 'understand' it. So I got: https:…

问题原文

原帖链接 · suz · CC BY-SA 3.0

I force usage of trailing slash for all of my pages under https://example.com, however the main domain remains without it - from what I've read it's OK to do so, but I'm not sure how does Google 'understand' it.

So I got:

  • https://example.com (https://example.com/ changes to https://example.com)

  • https://example.com/blog/

  • https://example.com/blog (which changes to https://example.com/blog/)

  • etc.

Questions:

  1. is it ok that my main page remains without trailing slash? From what I've observed it's typical behaviour of 99% domains.
  2. should I use in Google search console https://example.com or https://example.com/ ? Currently I got https://example.com/ and I wonder if it's a huge problem.
  3. Which one should I indicate in a sitemap? Currently I got https://example.com

If someone is interested, I paste also a part of my .htaccess file:

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

RewriteRule ^blog/$ sites/blog.php [NC,L]
RewriteRule ^mobile/$ index.php [NC,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]

已采纳解答

原帖链接 · MrWhite · CC BY-SA 3.0

When it comes to the "main domain" (ie. no apparent URL path) there is really only one URL. That is, the one with a trailing slash:

//example.com/

However, Google "understands" this and essentially "fixes" any URL where the slash is omitted. So, //example.com and //example.com/ are really the same. So, yes, it doesn't much matter.

Google always shows a trailing slash on the main domain in the SERPs.

Any URL you see in the browsers address bar where the trailing slash on the domain is omitted is purely cosmetic - in the browser. These days browsers are a bit notorious for making the visible URL look more friendly (omitting the scheme and even the query string in some browsers by default). However, if you look at the underlying request the browser is making, it is the same, regardless of whether you type the trailing slash or not. The trailing slash is present in the request (as the URL-path), because the HTTP request is simply not valid with an entirely "empty" URL-path.

https://domain.com (https://domain.com/ changes to https://domain.com)

To be clear, it is the browser that removes the trailing slash in the visible URL in the address bar, before the request is even sent to your server. As mentioned, this is purely cosmetic. Google Chrome and Firefox remove the trailing slash, IE11 does not. Opera removes the trailing slash (as well as the query string!) by default, however, this can be changed in Settings > User interface > "Show full URL in combined search and address bar" - you then get to see everything... the scheme, trailing slash on the domain and query string!

You've quoted your .htaccess code... However, your code is not doing anything with regards to slashes on the main domain. And nor can you influence the trailing slash on the main domain with server-side code.

To answer your specific questions...

  1. is it ok that my main page remains without trailing slash? From what I've observed it's typical behaviour of 99% domains.

This has nothing to do with the domain, or even your server. In order for the user agent to construct a valid HTTP request there must be a slash present in the URL-path. But yes, it's "OK".

  1. should I use in Google search console https://example.com or https://example.com/ ? Currently I got https://domain.com/ and I wonder if it's a huge problem.

I don't think you really have a choice. GSC automatically appends a trailing slash on the domain.

  1. Which one should I indicate in a sitemap? Currently I got https://example.com.

Strictly speaking you should include the trailing slash. The Google references I've seen, and the Sitemaps Protocol site itself all reference the main domain URL with a trailing slash. However, in reality it's not really going to matter. Any URL processing engine will "fix it".

Related question:
Is trailing slash automagically added on click of home page URL in browser?

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-10-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。