@@ -699,18 +699,24 @@ function wp_new_blog_notification() {
699699 // wp_guess_url() to construct incorrect URLs.
700700 $ url_parts = Utils \parse_url ( $ assoc_args ['url ' ] );
701701 $ path = isset ( $ url_parts ['path ' ] ) ? $ url_parts ['path ' ] : '/ ' ;
702- // Ensure path ends with index.php for proper WordPress URL detection
703- if ( '/ ' === $ path || '' === $ path ) {
702+
703+ // Ensure path represents a PHP script for proper WordPress URL detection.
704+ // If the path doesn't already end with a file (no extension in basename),
705+ // append '/index.php' to represent the WordPress entry point.
706+ $ path = rtrim ( $ path , '/ ' );
707+ if ( empty ( $ path ) ) {
704708 $ path = '/index.php ' ;
705- } elseif ( '/ ' === substr ( $ path , -1 ) ) {
706- $ path .= 'index.php ' ;
707709 } elseif ( false === strpos ( basename ( $ path ), '. ' ) ) {
708- // If path doesn't end with / and has no extension, add /index.php
709- $ path = rtrim ( $ path , ' / ' ) . '/index.php ' ;
710+ // Path doesn't end with a file, append /index.php
711+ $ path .= '/index.php ' ;
710712 }
713+
711714 $ _SERVER ['PHP_SELF ' ] = $ path ;
712715 $ _SERVER ['SCRIPT_NAME ' ] = $ path ;
713- // Set SCRIPT_FILENAME to the actual WordPress index.php path if it exists
716+
717+ // Set SCRIPT_FILENAME to the actual WordPress index.php if available.
718+ // This is optional and only set when ABSPATH is defined and index.php exists.
719+ // If not set, WordPress can still function using PHP_SELF and SCRIPT_NAME.
714720 if ( defined ( 'ABSPATH ' ) && file_exists ( ABSPATH . 'index.php ' ) ) {
715721 $ _SERVER ['SCRIPT_FILENAME ' ] = ABSPATH . 'index.php ' ;
716722 }
0 commit comments