Viewing 1 replies (of 1 total)
  • Thread Starter Thomas Szteliga

    (@websafepl)

    Hello,

    Apache & mod_rewrite is configured as it should be and mod_rewrite is working without problems on this vhost.

    The issue is WordPress is thinking, there’s no mod_rewrite available.

    WordPress is thinking this way, because it’s running under php-fpm and is using got_url_rewrite() to check, if rewrite is available.

    If you check  got_url_rewrite() you’ll see:

    function got_url_rewrite() {
    	$got_url_rewrite = ( got_mod_rewrite() || $GLOBALS['is_nginx'] || iis7_supports_permalinks() );
    

    and when you check got_mod_rewrite() | Function | WordPress Developer Resources, you’ll see:

    function got_mod_rewrite() {
    	$got_rewrite = apache_mod_loaded( 'mod_rewrite', true );

    and then, when you check apache_mod_loaded() | Function | WordPress Developer Resources you’ll see :

    function apache_mod_loaded( $mod, $default_value = false ) {
    	global $is_apache;
    
    	if ( ! $is_apache ) {
    		return false;
    	}
    
    	$loaded_mods = array();
    
    	if ( function_exists( 'apache_get_modules' ) ) {
    		$loaded_mods = apache_get_modules();
    
    		if ( in_array( $mod, $loaded_mods, true ) ) {
    			return true;
    		}
    	}
    
    	if ( empty( $loaded_mods )
    		&& function_exists( 'phpinfo' )
    		&& ! str_contains( ini_get( 'disable_functions' ), 'phpinfo' )
    	) {
    		ob_start();
    		phpinfo( INFO_MODULES );
    		$phpinfo = ob_get_clean();
    
    		if ( str_contains( $phpinfo, $mod ) ) {
    			return true;
    		}
    	}
    
    	return $default_value;
    }

    If this function returns false, WordPress will not detect mod_rewrite and index.php will be added to permalinks.

    The global $is_apache

    $is_apache = strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')

    will be false, because $_SERVER[‘SERVER_SOFTWARE’] will contain string(1) ” ” in PHP-FPM, so the result will be false, and finally got_url_rewrite() will return false, so WordPress will behave as if there is no mod_rewrite available, even if it is, just “one lever higher”.

    So in general my question is — is there a known quick solution, or should I simply rewrite the got_url_filter like this:

    add_filter('got_url_rewrite', 'enable_url_rewrite');
    function enable_url_rewrite($got_url_rewrite) {
        return true;
    }

    to force url rewriting in this case?

Viewing 1 replies (of 1 total)
  • The topic ‘php-fpm and got_url_rewrite thinks I have no mod_rewrite and adds index.php’ is closed to new replies.