Make WordPress Core

Opened 5 years ago

Closed 16 months ago

Last modified 16 months ago

#48367 closed defect (bug) (invalid)

wp-admin wrong links when doing php serve

Reported by: eduardoarandah's profile eduardoarandah Owned by:
Milestone: Priority: normal
Severity: minor Version: 5.2.3
Component: Administration Keywords: needs-patch reporter-feedback close
Focuses: Cc:

Description

Run a wordpress site locally with:

sudo php -S mysite.local:80

Login and navigate to:
http://mysite.local/wp-admin

wp-admin shows wrong menu links when URL don't have an ending /
http://mysite.local/wp-admin

menu links are correct when URL is like:
http://mysite.local/wp-admin/

menu links are also correct when URL is:
http://mysite.local/wp-admin/index.php

Example of wrong link:
http://mysite.local/options-general.php

instead of:
http://mysite.local/wp-admin/options-general.php

Change History (5)

#1 @donmhico
4 years ago

  • Keywords reporter-feedback added

Hello @eduardoarandah,

Thanks for the ticket and welcome in the WordPress Trac. I tried to replicate the issue but whenever I go in http://localhost:8889/wp-admin, i'm getting redirected to http://localhost:8889/wp-admin/

Request URL: http://localhost:8889/wp-admin
Request Method: GET
Status Code: 301 Moved Permanently
Remote Address: [::1]:8889
Referrer Policy: no-referrer-when-downgrade

Maybe you can give us more info about your environment.

#2 @markbranly
16 months ago

I replicated the issue using:

$ sudo php -S localhost:3000 

Visit http://localhost:3000/wp-admin yields:

GET: http://localhost:3000/wp-admin
Status: 200 OK
Version: HTTP/1.1
Transferred: 71.55 kB (71.01 kB size)
Referrer Policy: strict-origin-when-cross-origin
Request Priority: Highest
DNS Resolution: System

Curiously, links on the Admin Menu (#adminmenu) are broken, as OP stated, but links on the WP Admin Bar (#wpadminbar) are correct—edit comments, +New, profile links.

ETA: Versions:

PHP: 8.1.22
WP: 6.3

Last edited 16 months ago by markbranly (previous) (diff)

#3 @markbranly
16 months ago

So there are two issues here:

  1. WP should redirect to the canonical URL `/wp-admin/'.
  2. The links in the Admin Menu should work regardless, as they do in the WP Admin Bar.

As to the latter issue, the links in the Admin Menu are built as relative (https://core.trac.wordpress.org/browser/tags/6.3/src/wp-admin/menu-header.php#L68), assuming they are in the right directory. But, when the redirect fails, they are not. WP Admin Bar does not make this assumption and generates absolute URLs.

There is an existing ticket regarding relative links in the Admin Menu (#56302) with a proposed fix.

#4 @markbranly
16 months ago

  • Keywords close added
  • Resolution set to invalid
  • Status changed from new to closed

The first issue is actually a behavioral difference between the built-in PHP server and production servers like Apache and NGINX.

I created a simple folder with a subdir in my local's doc root. If a access the subdir with no slash it via Apache, it redirects and adds the slash. If I start a PHP server and access the subdir with no slash, it loads it as is.

Suggesting close ticket.

#5 @peterwilsoncc
16 months ago

  • Milestone Awaiting Review deleted

@markbranly and I are working together at the WCUS contributor day.

We've decided it's best to close this ticket without a code change as the cause comes from the use of the PHP built in web server.

We've closed this ticket as invalid which, in this case, is trac's unfriendly term to indicate that the root cause of the issue is from PHP rather than WP.

The related ticket #56302 will fix the issue when running WordPress on the built in PHP web server, so the issue of broken links will be resolved.

Note: See TracTickets for help on using tickets.