homepage – Do links to the home page need to be consistent about the trailing slash?

There is no need to be consistent. Links to your home page are 100% equivalent with and without the slash.

There is no way to make a valid HTTP request without a leading slash in the path. A (slightly simplified) request for your home page looks like:

GET / HTTP/1.1
Host: www.example.com

If your browser tried to make the request without the slash

Host: www.example.com

web servers would respond with a HTTP/1.1 400 Bad Request. As a result, browsers HAVE to send the slash when requesting the home page. If a home page URL, doesn’t have the slash, browsers always add it implicitly to the request. There are no redirects, extra requests, or performance problems involved.

I prefer to use the trailing slash for home page URLs. Because the slash is required to be sent, the more correct URL for the home page includes the slash. It also makes the home page URL more consistent with every other URL on your site. Every URL path starts with a slash.

Other people prefer to leave the slash off their home page URLs. There is merit to the argument that every unneeded piece of punctuation is uglier, hurts user experience, and consumes bandwidth. Browser URL bars often hide both the https:// and the trailing slash on the home page, showing only domain name to users.

There are no serious repercussions from choosing to use the trailing slash in links to your home page or to omit it. There are no problems with choosing the trailing slash in some links and choosing to omit it in others.

Trailing slashes matter on subdirectory URLs. There is a difference between example.com/foo and example.com/foo/. Those URLs are fetched distinctly, could have different content, and would require redirects to canonicalize. The home pages of your domain and subdomains are the only URLs on your site for which there is no technical difference between the versions with and without the trailing slash.

Is a subdomain home page URL with a trailing slash equivalent to without?

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

url – Homepages and trailing slashes

I have two questions regarding these pesky trailing slashes at the end of urls:

-example.com and example.com/ are equivalent, but what about subdomain homepages such as support.example.com and support.example.com/ ? Is it the same rule?

-If some pages on my website link to example.com and others link to example.com/ , should I make sure that all internal links point to one version, or it doesn’t matter?

Thank you.

Is there a program to remove trailing spaces and convert tabs to spaces in a lot of files at once using command-line?

I am using cygwin and have a lot of files in which I want to convert tabs to spaces and remove all space characters that exist at end of line. Is there a utility for this in Linux?

duplicate content – Trailing slash dups

Clearly, a slash or no slash define two different resources, except at the root level because the HTTP request can’t access the root without a slash.

The HTTP request for the root of a website looks like this:

GET / HTTP/1.1
Host: www.example.com

It’s just not technically possible to distinguish a version without a slash even if the URL syntax allows you to write it…

About a website hierarchy Google says:

When referring to the homepage, a trailing slash after the hostname is optional since it leads to the same content (https://example.com/ is the same as https://example.com). For the path and filename, a trailing slash would be seen as a different URL (signaling either a file or a directory), for example, https://example.com/fish is not the same as https://example.com/fish/.

Notice that here the author says “signaling either a file or a directory”. Another hint of the thought about slashes at Google.

Since file.html is referencing a file, it generally should not have a slash at the end (i.e. on a hard drive, you don’t put slashes at the end of filenames.) However, on the web you see it all and both appear here and there. I still think no slash is more common when you have an extension such as the .html.

I’ve seen CMS that place files attached to a page in a virtual sub-folder under that very page. So for example, if you had a recipe.pdf file, it could be:


Personally, I think it is weird to have a sub-directory under a .html because you can’t replicate that in a file system (in case you wanted later to create a static version of your website… you’d be in trouble with such virtual folders.)

A Google Example

Google had some examples about this problem (I’ll add the link if I find that page…) Their examples removed the extension as in:


(Note: Google says that they use the extension as a hint of the page’s contents, so file.html tells them that the content is most certainly HTML.)

So no slash at the end of what represents files, but when no extension is present, we get a folder and it makes sense to have a slash. So a complete list of the files could look like this:


Note: In the past, Google said that they would test parent folders automatically, even if the parent page is not defined in the sitemap.xml or in a link. So GoogleBot would check out all of the following:

# Found document:

# Also check parents:

However, I don’t recall ever seeing such hits in my logs. I never really look to prove that statement either. Yet, this means a functional parent is a good idea. Actually, as a user, I do that once in while, because when I see I’m in a certain sub-folder and think that I should be able to find things of interest one directory up, I manually try to go there by changing the URL. Website that break when you do that are definitely annoying.

When you save a webpage from Firefox or other browser, they create a sub-directory for all the files attached to the page (CSS, JS, images, etc.) and name it with the extension but change the period with an underscore. So something like this:


As for redirecting, it is not mandatory if your sitemap.xml and canonical are correct. In other words, if the search engines goes to:


but finds the following link meta tag:

<link rel="canonical" href="http://www.example.com/path/file.html"/>

then no 301 is required. Google & Co. will use the version without the slash.

The opposite is true too, of course. With the following, the slash version is saved and still no 301 is required:

<link rel="canonical" href="http://www.example.com/path/file.html/"/>

If you don’t have a proper canonical (or as I’ve seen on some CMS, if the code generating the canonical copies the URI as is–so you get two different pages in this case,) a redirect is probably the easiest way to fix the problem.

The sitemap.xml file must reference the page using the canonical URL of the page. So if the canonical uses the slash, the sitemap.xml URL will include the slash, and vice versa.

rewrite – nginx remove index.html, .html and trailing slash

I’m trying to setup nginx like the following:

website.com/index.html          --> website.com
website.com/somedir/index.html  --> website.com/somedir (no trailing slash)
website.com/somedir/log.html    --> website.com/somedir/log

I’ve tried about 500 rewrites in the last two days but none worked like rewrite all .html extension and remove index in Nginx which is my exact situation.

My current config is the following:

server {
    listen 80;
    server_name git.website.org;
    root /var/www/git.website.org;
    index index.html;

    rewrite ^(.+)/+$ $1 permanent;
    rewrite ^(.+)/index.html$ $1 permanent;
    try_files $uri $uri/index.html =404;

reference: Removing the trailing slash from a URL with nginx, the accepted answer

This config does serve the following correctly

website.com/index.html          --> website.com
website.com/somedir/index.html  --> website.com/somedir (no trailing slash)

however when I hover or click a link on /website.com/somedir (/website.com/somedir/index.html) for example to website.com/somedir/log.html, it appears as/goes to website.com/log.html, the subdirectory in the URL is removed.
Please help I’m at my wits end.

htaccess – Remove PHP extension from URLs such that the URLs work with or without a trailing slash

Your RewriteRule applied to http://example.org/about/ redirects to http://example.org/var/www/example/public_html/about/.php and result in a 404 Not Found response.

/var/www/example/public_html, or something similar, is the absolute path of the directory that contains the files of the website on the server. This type of path shows up because you did not start the Substitution (in your code: $1.php) with a /, which is mandatory in the .htaccess file in your case (read the ‘URL-path’ paragraph here).

To achieve your goal, I would use the following Apache httpd directives in the root .htaccess file (I assumed that all your webpages are PHP files):

# Tested with Apache httpd 2.4

RewriteCond %{REQUEST_URI} /$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+?)/$ /$1.php (END)

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

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule (.+/)?index.php$ /$1 (R=301,L)

RewriteRule (.+).php$ /$1/ (R=301,L)

seo – Worth moving WordPress to Apache hosting to fix trailing slash duplicate content on Pantheon under Nginx?

Context: As you might know, WordPress’ permalink structure enforces a trailing slash at the end of URLs (so /about becomes /about/ etc.)

I’ve always found this useful — keeps URLs nice and uniform.

My client’s WordPress site is hosted on Pantheon, which seems great except for one thing:

Their platform runs on Nginx, and for whatever reason that means the trailing slash permalink rule is not enforceable. (according to their support).

This means /about and /about/ both render in the browser. The canonical tag is set and points to /about/ — but to me, that’s still messy.

Support’s best answer was for me to write PHP redirects (which would have to be done on a 1:1 basis, for every URL on the site. This, to me, is not acceptable. It’s a basic issue and should be solvable — but it’s apparently not with Nginx.

I’m considering moving the site to a Linux host in order to resolve this issue, but I can’t find any definitive info on this.

Is it beneficial for SEO to solve the trailing slash issue and move to an Apache host? Or would it be a negligible improvement since there are already canonical tags (self-referencing) in place?

url rewriting – Cannot access wp-admin without trailing slash – .htaccess configuration for WordPress behind a nginx proxy

I have a WordPress instance running via http-proxy-middleware, so I can have my WordPress blog under example.com/blog

The problem I’m struggling with is I cannot configure the .htaccess file properly.

Here’s my config:

<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)

By default, WordPress generates all links without the trailing slash.

I can access the following:




But when I go to example.com/blog/wp-admin (no trailing slash) the redirection fails.

Same happens when I manually add the trailing slash to a post link:

example.com/blog/testing works

example.com/blog/testing/ fails

I wonder if I should focus on the http-proxy-middleware configuration or could it be that my .htaccess file is configured incorrectly?

How can I preserve trailing tab character in Nano?

I do have set autoindent in ~/.nanorc and it is auto-indenting as expected as I type. The issue I’m having is that any blank lines containing tab characters have those tabs stripped as trailing whitespace. Is there anything I can do to allow those tabs to be preserved?

Lets say I’m writing the following C program:

#include <stdio>

int main(int argc, char** args) {

    printf("Hello World!n");

    // I want to add something after this comment

    return 0;

Imagine that I decide to add another expression after printf("Hello World!n");

I move my cursor to the line I wish to start writing at and realize that I’m not indented correctly anymore. I want to stop nano from stripping the trailing whitespace, specifically tab characters.