WordPress.org

Make WordPress Core

Ticket #18852: 18852.3.patch

File 18852.3.patch, 7.9 KB (added by johnbillion, 6 years ago)
  • wp-admin/includes/misc.php

     
    1919}
    2020
    2121/**
     22 * Returns whether or not the server supports URL rewriting.
     23 *
     24 * @since 3.5
     25 *
     26 * @return bool Whether the server supports URL rewriting
     27 */
     28function got_url_rewrite() {
     29        global $is_nginx;
     30        $got_url_rewrite = ( got_mod_rewrite() or iis7_supports_permalinks() or $is_nginx );
     31        return apply_filters('got_url_rewrite', $got_url_rewrite);
     32}
     33
     34/**
    2235 * {@internal Missing Short Description}}
    2336 *
    2437 * @since 1.5.0
  • wp-admin/network.php

     
    314314 * @since 3.0.0
    315315 */
    316316function network_step2( $errors = false ) {
    317         global $base, $wpdb;
     317        global $base, $wpdb, $is_nginx;
    318318        $hostname = get_clean_basedomain();
    319319
    320320        if ( ! isset( $base ) )
     
    487487                </textarea></li>
    488488                </ol>
    489489
    490         <?php else : // end iis7_supports_permalinks(). construct an htaccess file instead:
     490        <?php elseif ( $is_nginx ) : // end iis7_supports_permalinks(). construct nginx configuration instead:
    491491
     492                $nginx_config_file = "location / {\n";
     493                $nginx_config_file .= "\t" . 'try_files $uri $uri/ /index.php$is_args$args;' . "\n";
     494                $nginx_config_file .= "}\n\n";
     495
     496                $nginx_config_file .= '# Uploaded files' . "\n";
     497                $nginx_config_file .= 'rewrite ^/' . ( $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) /wp-includes/ms-files.php?file=$2 last;' . "\n\n";
     498
     499                if ( ! $subdomain_install ) {
     500                        $nginx_config_file .= '# Add trailing slash to /wp-admin' . "\n";
     501                        $nginx_config_file .= 'rewrite /wp-admin$ $scheme://$host$uri/ permanent;' . "\n\n";
     502                        $nginx_config_file .= 'if (!-e $request_filename) {' . "\n";
     503                        $nginx_config_file .= "\t" . 'rewrite ^/[_0-9a-zA-Z-]+(/wp-(content|admin|includes).*) $1 last;' . "\n";
     504                        $nginx_config_file .= "\t" . 'rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;' . "\n";
     505                        $nginx_config_file .= "}\n";
     506                }
     507
     508        ?>
     509                <li><p><?php _e( 'Add the following to your <code>nginx.conf</code> file (or equivalent), replacing other WordPress rules:' ); ?></p>
     510                <textarea class="code" readonly="readonly" cols="100" rows="20">
     511<?php echo esc_textarea( $nginx_config_file ); ?></textarea></li>
     512                </ol>
     513
     514        <?php else : // end nginx. construct an htaccess file instead:
     515
    492516                $htaccess_file = 'RewriteEngine On
    493517RewriteBase ' . $base . '
    494518RewriteRule ^index\.php$ - [L]
     
    515539<?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
    516540                </ol>
    517541
    518         <?php endif; // end IIS/Apache code branches.
     542        <?php endif; // end IIS/nginx/Apache code branches.
    519543
    520544        if ( !is_multisite() ) { ?>
    521545                <p><?php printf( __( 'Once you complete these steps, your network is enabled and configured. You will have to log in again.') ); ?> <a href="<?php echo esc_url( site_url( 'wp-login.php' ) ); ?>"><?php _e( 'Log In' ); ?></a></p>
  • wp-admin/options-permalink.php

     
    7878$iis7_permalinks = iis7_supports_permalinks();
    7979
    8080$prefix = $blog_prefix = '';
    81 if ( ! got_mod_rewrite() && ! $iis7_permalinks )
     81if ( ! got_url_rewrite() )
    8282        $prefix = '/index.php';
    8383if ( is_multisite() && !is_subdomain_install() && is_main_site() )
    8484        $blog_prefix = '/blog';
     
    128128                $writable = true;
    129129        else
    130130                $writable = false;
     131} else if ( $is_nginx ) {
     132        $writable = false;
    131133} else {
    132134        if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') )
    133135                $writable = true;
     
    152154                        _e('Permalink structure updated. Remove write access on web.config file now!');
    153155                else
    154156                        _e('Permalink structure updated.');
    155         } else {
     157                } else if ( $is_nginx ) {
     158                        if ( $permalink_structure )
     159                                _e('Permalink structure updated. Ensure your nginx.conf file (or equivalent) contains the rewrite rules below.');
     160                        else
     161                                _e('Permalink structure updated.');
     162                } else {
    156163                if ( $permalink_structure && ! $usingpi && ! $writable )
    157164                        _e('You should update your .htaccess now.');
    158165                else
     
    225232</table>
    226233
    227234<h3><?php _e('Optional'); ?></h3>
    228 <?php
    229 $suffix = '';
    230 if ( ! $is_apache && ! $iis7_permalinks )
    231         $suffix = 'index.php/';
    232 ?>
    233235<p><?php
    234 /* translators: %s is a placeholder that must come at the start of the URL path. */
    235 printf( __('If you like, you may enter custom structures for your category and tag <abbr title="Universal Resource Locator">URL</abbr>s here. For example, using <code>topics</code> as your category base would make your category links like <code>http://example.org/%stopics/uncategorized/</code>. If you leave these blank the defaults will be used.'), $suffix ); ?></p>
     236/* translators: %s is the site URL. */
     237printf( __('If you like, you may enter custom structures for your category and tag <abbr title="Universal Resource Locator">URL</abbr>s here. For example, using <code>topics</code> as your category base would make your category links like <code>%s/topics/uncategorized/</code>. If you leave these blank the defaults will be used.'), home_url( $prefix . $blog_prefix ) ); ?></p>
    236238
    237239<table class="form-table">
    238240        <tr>
     
    269271<p><?php _e('If you temporarily make your site&#8217;s root directory writable for us to generate the <code>web.config</code> file automatically, do not forget to revert the permissions after the file has been created.') ?></p>
    270272                <?php endif; ?>
    271273        <?php endif; ?>
     274<?php elseif ( $is_nginx ) :
     275        if ( $permalink_structure && ! $usingpi ) : ?>
     276<p><?php _e('These are the rewrite rules you should have in your <code>nginx.conf</code> (or equivalent) file. Click in the field and press <kbd>CTRL + a</kbd> to select all.') ?></p>
     277<form action="options-permalink.php" method="post">
     278<?php wp_nonce_field('update-permalink') ?>
     279        <p><textarea rows="4" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->nginx_url_rewrite_rules() ); ?></textarea></p>
     280</form>
     281        <?php endif; ?>
    272282<?php else :
    273283        if ( $permalink_structure && ! $usingpi && ! $writable ) : ?>
    274284<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>
  • wp-includes/rewrite.php

     
    18091809        }
    18101810
    18111811        /**
     1812         * Retrieve Nginx formatted rewrite rules.
     1813         *
     1814         * @since 3.5
     1815         * @access public
     1816         *
     1817         * @return string
     1818         */
     1819        function nginx_url_rewrite_rules() {
     1820                if ( ! $this->using_permalinks() )
     1821                        return '';
     1822
     1823                $rules = "location / {\n";
     1824                $rules .= "\t" . 'try_files $uri $uri/ /index.php$is_args$args;' . "\n";
     1825                $rules .= "}\n";
     1826
     1827                $rules = apply_filters('nginx_rewrite_rules', $rules);
     1828
     1829                return $rules;
     1830        }
     1831
     1832        /**
    18121833         * Add a straight rewrite rule.
    18131834         *
    18141835         * Any value in the $after parameter that isn't 'bottom' will be placed at
  • wp-includes/vars.php

     
    8787$is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);
    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
    9298 */