Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing slash on URLs #170

Closed
dgursh opened this issue Nov 9, 2017 · 8 comments
Closed

Trailing slash on URLs #170

dgursh opened this issue Nov 9, 2017 · 8 comments

Comments

@dgursh
Copy link
Contributor

dgursh commented Nov 9, 2017

I just deployed a site to Amazon S3, however I noticed that all of the URLs end with a trailing slash like so:

example.com/dir/

On my local machine it does not have a trailing slash

example.com/dir

Why is it doing this? Is there anyway to fix this behavior? I believe Amazon S3 is treating the jigsaw folders like directories and then just assuming index.html is the file. Need to fix for SEO. Any suggestions? Thanks.

@dgursh
Copy link
Contributor Author

dgursh commented Nov 9, 2017

I guess I can just turn --pretty=false

But then I'm stuck with .html

I'm confused why a trailing slash exists on Amazon S3, but not on localhost

@damiani
Copy link
Contributor

damiani commented Nov 15, 2017

This is S3's behavior; it hits example.com/dir and if no object exists there (it doesn't), it tries example.com/dir/index.html. In a Jigsaw site, that object does exist, and that's what it serves, using the URL example.com/dir/.

It should have no SEO effect, however. According to Google, at least:

http://example.com/foo/ (with trailing slash, conventionally a directory)
http://example.com/foo (without trailing slash, conventionally a file)
Google treats each URL above separately (and equally) regardless of whether it’s a file or a directory, or it contains a trailing slash or it doesn’t contain a trailing slash.

@damiani damiani closed this as completed Nov 15, 2017
@GitHub-Mike
Copy link

Here is a (late) solution to the problem for apache users. Add the following lines to the .htaccess:

DirectorySlash Off

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_FILENAME}/index.html -f
RewriteRule (.*) $1/index.html [L]

@chrisvidal
Copy link

digging up this thread

the following snipper is not working for my apache 2.
Google search console is giving lots of page with redirect issue because of this trailing slash.

any idea how to fix this?

DirectorySlash Off

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_FILENAME}/index.html -f
RewriteRule (.*) $1/index.html [L]

@GitHub-Mike
Copy link

the following snipper is not working for my apache 2. Google search console is giving lots of page with redirect issue because of this trailing slash.

Does the snippet really not work?

The messages in the GSC can also have other reasons.

@chrisvidal
Copy link

chrisvidal commented Mar 31, 2024

this .htaccess snippet does not seem to be working for me,

when I type in the url domain.com/page it returns back to domain.com/page/

DirectorySlash Off

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_FILENAME}/index.html -f
RewriteRule (.*) $1/index.html [L]

EDIT: wait a sec., I made a typo in the .htaccess filename there it was not taken into account.
now it seems to be working :) except for subs sub pages

when I type in the url domain.com/page/subpage it returns back to domain.com/page/subpage/

@GitHub-Mike
Copy link

GitHub-Mike commented Apr 4, 2024

when I type in the url domain.com/page/subpage it returns back to domain.com/page/subpage/

I have just tested this, but cannot confirm the behaviour.

"DirectorySlash Off" also applies to subdirectories. Unless there are special instructions for this subdirectory from this or another .htaccess file.

https://httpd.apache.org/docs/current/howto/htaccess.html#how

What happens if you place an .htaccess file with the content:

DirectorySlash Off

in this subdirectory?

@chrisvidal
Copy link

chrisvidal commented Apr 4, 2024

Now it's working, I haven't change anything.

I think I found the reason because of the structured directories and files, I had this:

/programs/martial-arts/index.blade.php <=
/programs/martial-arts/martial-arts-for-kids.blade.php
/programs/martial-arts/martial-arts-for-adults.blade.php

then I changed to

/programs/martial-arts.blade.php <=
/programs/martial-arts/martial-arts-for-kids.blade.php
/programs/martial-arts/martial-arts-for-adults.blade.php

and it works fine now for the intermediary folders

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants