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

Redirect /wp-admin to /wp-admin/ as not to break the admin navigation menu #461

Closed
KeesCBakker opened this issue May 28, 2023 · 11 comments · Fixed by WordPress/playground-tools#60
Labels
[Type] Enhancement New feature or request

Comments

@KeesCBakker
Copy link

When I use http://127.0.0.1:8881/wp-admin, I get a nice page:

image

But all of my links of my menu break:

image

So I end up on the wrong page:

image

Easy solution: redirect /wp-admin to /wp-admin/. Looks like my "normal" WordPress does this by itself.

@KeesCBakker
Copy link
Author

Come to think of it, this might be some kind of PHP.ini or http config apache thingy, where it appends a trailing slash to some paths...

@adamziel
Copy link
Collaborator

Playground in the browser handles that in the address bar handler. A better solution would involve an isomorphic WordPress request handler for all Playground consumers.

@adamziel adamziel added [Type] Enhancement New feature or request and removed Local Environment labels May 28, 2023
@dmsnell
Copy link
Collaborator

dmsnell commented May 29, 2023

@KeesCBakker I think so, because when I run WordPress locally with php -S it does the same thing. I've "found out" a couple times why it happens, but I always forget why. I think you are right with the /. That is to say, this is not caused by the Playground; probably a quirk exposed by these less-common environments in which WordPress runs.

Maybe we could find the culprit in some server config and set that as a Playground default.

@sejas
Copy link
Collaborator

sejas commented Jun 2, 2023

@adamziel
Copy link
Collaborator

adamziel commented Jun 2, 2023

Reopening since there is a fix in wp-now, but there isn’t yet a general fix that would work for all Playground-based apps.

@adamziel adamziel reopened this Jun 2, 2023
@KeesCBakker
Copy link
Author

@sejas thanks for fixing this!

@eliot-akira
Copy link
Collaborator

eliot-akira commented Jun 19, 2023

a general fix that would work for all Playground-based apps

The Playground client's goTo() method specifically rewrites /wp-admin to /wp-admin/.

if (requestedPath === '/wp-admin') {
	requestedPath = '/wp-admin/';
}
wpFrame.src = await playground.pathToInternalUrl(requestedPath);

(In packages/playground/remote/src/lib/boot-playground-remote.ts)

It seems that solves the issue in general, at least on the browser side. Except for Playground-based apps that set the iframe src directly instead of using goTo().

@adamziel
Copy link
Collaborator

adamziel commented Jun 19, 2023

@eliot-akira I was thinking about some rewriting mechanism at the request handler level to also support nice permalinks regardless of how that request reached WordPress. At the moment, building a wp-now clone would require reimplementing the rewriting logic.

@eliot-akira
Copy link
Collaborator

eliot-akira commented Jun 19, 2023

rewriting mechanism at the request handler level

That makes sense to solve it deeper in the core, so that "consumers" like wp-now, the Playground client's goTo method, or the address bar, don't need to work around it.

I think rewriting URL to add a trailing slash automatically is often done by server configuration. Come to think of it, it's weird that /wp-admin results in broken links in the admin menu. It seems like something that should be handled by WordPress itself (like redirect to canonical URL), instead of relying on Apache/NGINX, a php.ini directive, or the Playground's request handler to add the slash.

@sejas
Copy link
Collaborator

sejas commented Jun 23, 2023

I am unassigning myself from this issue because I don't have the bandwidth to move it forward in the near future.
I agree that a fix on Core would be a more general fix.

@sejas sejas removed their assignment Jun 23, 2023
@brandonpayton
Copy link
Member

This was fixed by #1539 in a general way here:

// This behavior is also necessary for WordPress to function properly.
// Otherwise, when viewing the WP admin dashboard at `/wp-admin`,
// links to other admin pages like `edit.php` will incorrectly
// resolve to `/edit.php` rather than `/wp-admin/edit.php`.
if (!fsPath.endsWith('/')) {
return new PHPResponse(
301,
{ Location: [`${requestedUrl.pathname}/`] },
new Uint8Array(0)
);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants