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

Automatically redirect http://host/folder to http://host/folder/ #1907

Closed

Conversation

paulharris
Copy link
Contributor

This will then automatically look for the /index.html file.

This fixes #1389

This will then automatically look for the /index.html file.
@paulharris
Copy link
Contributor Author

I wonder if #1848 will also be fixed with this?

Comment on lines 6475 to +6477
if (path.back() == '/') { path += "index.html"; }

if (detail::is_dir(path)) {
Copy link
Contributor

@sergio-nsk sergio-nsk Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it should also have the opposite part

Suggested change
if (path.back() == '/') { path += "index.html"; }
if (detail::is_dir(path)) {
if (path.back() == '/') {
path.pop_back();
if (detail::is_file(path)) {
sub_path.pop_back();
res.set_redirect(sub_path);
return true;
}
path += "/index.html"; }
} else if (detail::is_dir(path)) {

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's correct.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example.com does that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NGINX doesn't redirect file to file/ either, but returns as 404.

image

@yhirose
Copy link
Owner

yhirose commented Sep 3, 2024

I wonder if #1848 will also be fixed with this?

The pull request may fix #1848 though, the real cause of the issue is a problem with detail::is_file on Windows.
I have just fixed it.

@yhirose
Copy link
Owner

yhirose commented Sep 3, 2024

@paulharris could you please provide at least one unit test case in test/test.cc? Thanks!

yhirose added a commit that referenced this pull request Sep 5, 2024
@yhirose
Copy link
Owner

yhirose commented Sep 5, 2024

@paulharris I added some test cases and adjust your code to return 301 instead of 302. Thanks for your contribution!

@yhirose yhirose closed this Sep 5, 2024
@paulharris
Copy link
Contributor Author

My apologies for the late reply, it was circling back to this but I'm very happy that you liked it and cleaned it up.

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

Successfully merging this pull request may close these issues.

Accessing Directory
3 participants