WordPress.org

Make WordPress Core

Changeset 25456


Ignore:
Timestamp:
09/16/2013 08:06:27 PM (7 years ago)
Author:
nacin
Message:

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.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/misc.php

    r24762 r25456  
    88
    99/**
    10  * {@internal Missing Short Description}}
     10 * Returns whether the server is running Apache with the mod_rewrite module loaded.
    1111 *
    1212 * @since 2.0.0
    1313 *
    14  * @return unknown
     14 * @return bool
    1515 */
    1616function got_mod_rewrite() {
    1717    $got_rewrite = apache_mod_loaded('mod_rewrite', true);
     18
     19    /**
     20     * Filter whether Apache and mod_rewrite are present.
     21     *
     22     * This filter was previously used to force URL rewriting for other servers,
     23     * like nginx. Use the got_url_rewrite filter in got_url_rewrite() instead.
     24     *
     25     * @see got_url_rewrite()
     26     *
     27     * @since 2.5.0
     28     * @param bool $got_rewrite Whether Apache and mod_rewrite are present.
     29     */
    1830    return apply_filters('got_rewrite', $got_rewrite);
     31}
     32
     33/**
     34 * Returns whether the server supports URL rewriting.
     35 *
     36 * Detects Apache's mod_rewrite, IIS 7.0+ permalink support, and nginx.
     37 *
     38 * @since 3.7.0
     39 *
     40 * @return bool Whether the server supports URL rewriting.
     41 */
     42function got_url_rewrite() {
     43    $got_url_rewrite = ( got_mod_rewrite() || $GLOBALS['is_nginx'] || iis7_supports_permalinks() );
     44
     45    /**
     46     * Filter whether URL rewriting is available.
     47     *
     48     * @since 3.7.0
     49     * @param bool $got_url_rewrite Whether URL rewriting is available.
     50     */
     51    return apply_filters( 'got_url_rewrite', $got_url_rewrite );
    1952}
    2053
  • trunk/src/wp-admin/options-permalink.php

    r25206 r25456  
    7676
    7777$prefix = $blog_prefix = '';
    78 if ( ! got_mod_rewrite() && ! $iis7_permalinks )
     78if ( ! got_url_rewrite() )
    7979    $prefix = '/index.php';
    8080if ( is_multisite() && !is_subdomain_install() && is_main_site() )
     
    127127    else
    128128        $writable = false;
     129} elseif ( $is_nginx ) {
     130    $writable = false;
    129131} else {
    130132    if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') )
     
    153155        else
    154156            _e('Permalink structure updated.');
     157    } elseif ( $is_nginx ) {
     158        _e('Permalink structure updated.');
    155159    } else {
    156160        if ( $permalink_structure && ! $usingpi && ! $writable )
     
    227231<h3 class="title"><?php _e('Optional'); ?></h3>
    228232<?php
    229 $suffix = '';
    230 if ( ! $is_apache && ! $iis7_permalinks )
    231     $suffix = $wp_rewrite->index . '/';
     233$suffix = $prefix;
     234if ( $suffix )
     235    $suffix = ltrim( $suffix, '/' ) . '/';
    232236?>
    233237<p><?php
     
    270274        <?php endif; ?>
    271275    <?php endif; ?>
    272 <?php else :
     276<?php elseif ( ! $is_nginx ) :
    273277    if ( $permalink_structure && ! $usingpi && ! $writable ) : ?>
    274278<p><?php _e('If your <code>.htaccess</code> file were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so these are the mod_rewrite rules you should have in your <code>.htaccess</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all.') ?></p>
  • trunk/src/wp-includes/vars.php

    r24594 r25456  
    8888
    8989/**
     90 * Whether the server software is Nginx or something else
     91 * @global bool $is_nginx
     92 */
     93$is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false);
     94 
     95/**
    9096 * Whether the server software is IIS or something else
    9197 * @global bool $is_IIS
Note: See TracChangeset for help on using the changeset viewer.