I have been working on getting pretty permalinks[1] to work properly in
httpd. The WordPress project publishes configurations for Apache and
nginx.[2]
I have a slightly better but still very weak grasp of nginx, so here is
the key part of nginx.conf, as I understand it, for supporting pretty
permalinks:
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break
when using query string
try_files $uri $uri/ /index.php?$args;
}
My attempt to match nginx functionality in httpd.conf:
location "/" {
request rewrite "/index.php?$QUERY_STRING"
}
location not found "/*" {
request rewrite "/index.php?$REQUEST_URI"
}
I have also added lines to
wp-content/themes/twentytwentyfive/functions.php:
These lines[3]:
function wpse427660_got_rewrite() {
return true;
}
add_filter( 'got_url_rewrite', 'wpse427660_got_rewrite' );
Or this line:
$is_nginx = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) ||
str_contains( $_SERVER['SERVER_SOFTWARE'], 'OpenBSD httpd' ) );
Using one or the other (not both at the same time) are so far as I can
tell both the same in how WordPress ends up being served.
If anyone familiar with both httpd and nginx can enlighten to the
differences between the behavior of the web servers in this regard, I
would really appreciate it.
Also, if anyone else has worked on getting httpd to support WordPress
pretty permalinks, did you review through the WordPress code? I am still
getting the site health error "The REST API did not process the context
query parameter correctly."
As far I can tell, WordPress detects nginx in wp-includes/vars.php.[4]
And supports the URL rewrite in wp-admin/includes/misc.php.[5]
WordPress does a bunch of other stuff when it detects nginx as a PHP
variable.[6]
Thank you,
Paul
[1] https://wordpress.org/documentation/article/customize-permalinks/
[2]
https://developer.wordpress.org/advanced-administration/server/web-server/
[3] https://wordpress.stackexchange.com/a/427664/47317
[4]
https://github.com/WordPress/wordpress-develop/blob/1aa41dea3345c57cffce9059bbad728c86d1471a/src/wp-includes/vars.php#L127
[5]
https://github.com/WordPress/wordpress-develop/blob/1aa41dea3345c57cffce9059bbad728c86d1471a/src/wp-admin/includes/misc.php#L46
[6]
https://github.com/search?q=repo%3AWordPress%2Fwordpress-develop%20is_nginx&type=code