From d3b89d43fc624076a4002f08ce1f871a7fa9af3f Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 16 Sep 2013 20:07:09 +0000 Subject: [PATCH] Add nginx detection to the Permalink Settings screen. Introduces got_url_rewrite() and a corresponding filter, which should now be used in lieu of the got_rewrite filter in got_mod_rewrite(). This does not write or even suggest nginx configuration; rather, it prevents nginx from being considered as either Apache or as an unrecognized server. props johnbillion. fixes #25098. Built from https://develop.svn.wordpress.org/trunk@25456 git-svn-id: http://core.svn.wordpress.org/trunk@25377 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/misc.php | 37 ++++++++++++++++++++++++++++++++-- wp-admin/options-permalink.php | 14 ++++++++----- wp-includes/vars.php | 6 ++++++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index 5b609e45ba..13382754e7 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -7,17 +7,50 @@ */ /** - * {@internal Missing Short Description}} + * Returns whether the server is running Apache with the mod_rewrite module loaded. * * @since 2.0.0 * - * @return unknown + * @return bool */ function got_mod_rewrite() { $got_rewrite = apache_mod_loaded('mod_rewrite', true); + + /** + * Filter whether Apache and mod_rewrite are present. + * + * This filter was previously used to force URL rewriting for other servers, + * like nginx. Use the got_url_rewrite filter in got_url_rewrite() instead. + * + * @see got_url_rewrite() + * + * @since 2.5.0 + * @param bool $got_rewrite Whether Apache and mod_rewrite are present. + */ return apply_filters('got_rewrite', $got_rewrite); } +/** + * Returns whether the server supports URL rewriting. + * + * Detects Apache's mod_rewrite, IIS 7.0+ permalink support, and nginx. + * + * @since 3.7.0 + * + * @return bool Whether the server supports URL rewriting. + */ +function got_url_rewrite() { + $got_url_rewrite = ( got_mod_rewrite() || $GLOBALS['is_nginx'] || iis7_supports_permalinks() ); + + /** + * Filter whether URL rewriting is available. + * + * @since 3.7.0 + * @param bool $got_url_rewrite Whether URL rewriting is available. + */ + return apply_filters( 'got_url_rewrite', $got_url_rewrite ); +} + /** * {@internal Missing Short Description}} * diff --git a/wp-admin/options-permalink.php b/wp-admin/options-permalink.php index e045982b28..d8d454cdb6 100644 --- a/wp-admin/options-permalink.php +++ b/wp-admin/options-permalink.php @@ -75,7 +75,7 @@ $home_path = get_home_path(); $iis7_permalinks = iis7_supports_permalinks(); $prefix = $blog_prefix = ''; -if ( ! got_mod_rewrite() && ! $iis7_permalinks ) +if ( ! got_url_rewrite() ) $prefix = '/index.php'; if ( is_multisite() && !is_subdomain_install() && is_main_site() ) $blog_prefix = '/blog'; @@ -126,6 +126,8 @@ if ( $iis7_permalinks ) { $writable = true; else $writable = false; +} elseif ( $is_nginx ) { + $writable = false; } else { if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') ) $writable = true; @@ -152,6 +154,8 @@ if ( ! is_multisite() ) { _e('Permalink structure updated. Remove write access on web.config file now!'); else _e('Permalink structure updated.'); + } elseif ( $is_nginx ) { + _e('Permalink structure updated.'); } else { if ( $permalink_structure && ! $usingpi && ! $writable ) _e('You should update your .htaccess now.'); @@ -226,9 +230,9 @@ $structures = array(

index . '/'; +$suffix = $prefix; +if ( $suffix ) + $suffix = ltrim( $suffix, '/' ) . '/'; ?>

web.config file automatically, do not forget to revert the permissions after the file has been created.') ?>

-

.htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press CTRL + a to select all.') ?>

diff --git a/wp-includes/vars.php b/wp-includes/vars.php index f55cdbd9fd..1eac8081de 100644 --- a/wp-includes/vars.php +++ b/wp-includes/vars.php @@ -86,6 +86,12 @@ $is_IE = ( $is_macIE || $is_winIE ); */ $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false); +/** + * Whether the server software is Nginx or something else + * @global bool $is_nginx + */ +$is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false); + /** * Whether the server software is IIS or something else * @global bool $is_IIS