WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.52k stars 4.21k forks source link

Site title block links to wrong home url causing a useless redirect #65670

Open Chouby opened 1 month ago

Chouby commented 1 month ago

Description

When WordPress is installed in a subfolder, the home url is let say https://mysite.com/wordpress/ with a trailing slash. However the site title block links to https://mysite.com/wordpress without trailing slash which is then redirected to the canonical url https://mysite.com/wordpress/.

The same kind of issue occurs for multisite where sites are installed in folders.

Step-by-step reproduction instructions

  1. Install WordPress in a subfolder with a default theme.
  2. Create a page and insert the site title block
  3. View the page on frontend
  4. Open the browser tools to observe that there will be a redirect.
  5. Check the link proposed by the site title block is https://mysite.com/wordpress
  6. Click on the link and observe that there is 301 redirect from https://mysite.com/wordpress to https://mysite.com/wordpress/

Screenshots, screen recording, code snippet

No response

Environment info

WP 6.6 + Twenty Twenty Four

Please confirm that you have searched existing issues in the repo.

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Mamaduka commented 1 month ago

Hi, @Chouby

The Site Title block uses the home_url function as the link. This could be an issue with the WP subfolder installation itself, or there's a filter that modifies the home_url behavior.

What result do you get if you run echo home_url()?

Chouby commented 1 month ago

Hi @Mamaduka, You went too fast for me ;). I was preparing the PR to add the slash in home_url(). When I run echo home_url(), I get https://mysite.com/wordpress. When I run echo home_url( '/' ), I get https://mysite.com/wordpress/.

Mamaduka commented 1 month ago

Thank you, @Chouby!

I checked similar usages in WP core, like "Visit Site" in the admin bar, and it's using a trailing slash, which seems like the correct solution.

Here's the old core ticket for a similar issue: https://core.trac.wordpress.org/ticket/19314.

Also, I think we should update the Home Link block. Would you mind including it in your PR?

cc @SergeyBiryukov

Chouby commented 1 month ago

Done for the home Link block too.