How does WordPress determine if a server supports pretty permalinks?

admin2025-01-07  4

I am trying to get pretty permalinks to function with OpenBSD httpd.

However, I cannot test my configurations because WordPress only offers the option of almost pretty permalinks.

What does WordPress use to determine if it should offer pretty permalinks as a configuration option?

If an answer or comment isn't explaining how WordPress performs this test, then it is not addressing the question.

I am trying to get pretty permalinks to function with OpenBSD httpd.

However, I cannot test my configurations because WordPress only offers the option of almost pretty permalinks.

What does WordPress use to determine if it should offer pretty permalinks as a configuration option?

If an answer or comment isn't explaining how WordPress performs this test, then it is not addressing the question.

Share Improve this question edited Nov 22, 2024 at 15:58 Paul asked Nov 22, 2024 at 12:06 PaulPaul 1741 silver badge9 bronze badges 10
  • what does it mean "almost pretty permalinks." – Mark Kaplun Commented Nov 22, 2024 at 12:36
  • Almost pretty permalinks use the format http://example.com/index.php/yyyy/mm/dd/post-name/. See wordpress.org/documentation/article/customize-permalinks for more information. – Paul Commented Nov 22, 2024 at 12:40
  • if you want an answer you should put all details in your question, for example what is your web server (appach,ngix, lightspeed, other) and what is its configuration. at least in terms of relevant moduls – Mark Kaplun Commented Nov 22, 2024 at 12:45
  • I stated in the question that the server software is OpenBSD httpd. If you are not familiar with this, that is okay, but note that I have gone very deep in search results and the current version of OpenBSD (or any version that supports rewrite rules) httpd, there is not a single post anywhere that has a configuration to support WordPress pretty permalinks. So I seem to be a trailblazer and the first problem I'm running into is WordPress doesn't offer the option of pretty permalinks, so I cannot tell if the configuration would work or not. – Paul Commented Nov 22, 2024 at 12:49
  • I am able to find many screenshots of the WordPress permalinks page in the dashboard and that page shows options that are already in the pretty permalinks format. This seems to indicate that WordPress has something it uses to determine that the server supports pretty permalinks, so the server configuration is not directly relevant to the test, as the test is being performed by WordPress, itself, and that is the thing I am trying to discover. – Paul Commented Nov 22, 2024 at 12:55
 |  Show 5 more comments

2 Answers 2

Reset to default 3

Given that httpd is a very minor webserver by market share and didn't support rewrites until OpenBSD 6.6, it's not really surprising that WP hasn't been written to accommodate it.

The basic structure that WP requires is if the request is not for an extant file or directory, to rewrite it to index.php in the root of the site. You're going to have to implement that yourself. The guide at openbsdhandbook.com only acknowledges OpenBSD 6.4, so obviously there's no mention there of how it implements rewrites.

Otherwise, it might be a better idea to use a supported and better documented webserver like nginx.

Digging into it a little further: the actual test for rewriting is carried out by got_url_rewrite(), which by default returns true if one of the below conditions is satisfied:

  • Apache's mod_rewrite module is loaded
  • $GLOBALS['is_nginx'] is set
  • $GLOBALS['is_caddy'] is set
  • iis7_supports_permalinks() returns true

Provided you have rewrites correctly configured the below should work for you:

function wpse427660_got_rewrite() {
    return true;
}

add_filter( 'got_url_rewrite', 'wpse427660_got_rewrite' );

Another option is to use $is_nginx by placing the following line in functions.php:

<?php

$is_nginx = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'OpenBSD httpd' ));

This will force WordPress to respond the same as it would with nginx as it is the same test performed for nginx in vars.php[1]:

$is_nginx = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) );

Other things impacted by this can be discovered by searching the code base for is_nginx.

[1] https://github.com/WordPress/wordpress-develop/blob/6.7.1/src/wp-includes/vars.php#L127

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736260793a690.html

最新回复(0)