WordPress.org

Make WordPress Core

Ticket #18852: 18852.2.patch

File 18852.2.patch, 5.5 KB (added by johnbillion, 3 years ago)
  • wp-admin/includes/misc.php

     
    1919} 
    2020 
    2121/** 
     22 * Returns whether or not the server supports URL rewriting. 
     23 * 
     24 * @since 3.3 
     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/options-permalink.php

     
    5959$iis7_permalinks = iis7_supports_permalinks(); 
    6060 
    6161$prefix = $blog_prefix = ''; 
    62 if ( ! got_mod_rewrite() && ! $iis7_permalinks ) 
     62if ( ! got_url_rewrite() ) 
    6363        $prefix = '/index.php'; 
    6464if ( is_multisite() && !is_subdomain_install() && is_main_site() ) 
    6565        $blog_prefix = '/blog'; 
     
    109109                $writable = true; 
    110110        else 
    111111                $writable = false; 
     112} else if ( $is_nginx ) { 
     113        $writable = false; 
    112114} else { 
    113115        if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') ) 
    114116                $writable = true; 
     
    123125 
    124126$wp_rewrite->flush_rules(); 
    125127 
    126  
    127128if (isset($_POST['submit'])) : ?> 
    128129<div id="message" class="updated"><p><?php 
    129130if ( ! is_multisite() ) { 
     
    134135                        _e('Permalink structure updated. Remove write access on web.config file now!'); 
    135136                else 
    136137                        _e('Permalink structure updated'); 
     138        } else if ( $is_nginx ) { 
     139                if ( $permalink_structure ) 
     140                        _e('Permalink structure updated. Ensure your nginx.conf (or equivalent) contains the rewrite rules below.'); 
     141                else 
     142                        _e('Permalink structure updated.'); 
    137143        } else { 
    138144                if ( $permalink_structure && ! $usingpi && ! $writable ) 
    139145                        _e('You should update your .htaccess now.'); 
     
    207213</table> 
    208214 
    209215<h3><?php _e('Optional'); ?></h3> 
    210 <?php if ( $is_apache || $iis7_permalinks ) : ?> 
     216<?php if ( $is_apache || $iis7_permalinks || $is_nginx ) : ?> 
    211217        <p><?php _e('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 <kbd>topics</kbd> as your category base would make your category links like <code>http://example.org/topics/uncategorized/</code>. If you leave these blank the defaults will be used.') ?></p> 
    212218<?php else : ?> 
    213219        <p><?php _e('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/index.php/topics/uncategorized/</code>. If you leave these blank the defaults will be used.') ?></p> 
     
    248254<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> 
    249255                <?php endif; ?> 
    250256        <?php endif; ?> 
     257<?php elseif ( $is_nginx ) : 
     258        if ( $permalink_structure && ! $usingpi ) : ?> 
     259<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> 
     260<form action="options-permalink.php" method="post"> 
     261<?php wp_nonce_field('update-permalink') ?> 
     262        <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> 
     263</form> 
     264        <?php endif; ?> 
    251265<?php else : 
    252266        if ( $permalink_structure && ! $usingpi && ! $writable ) : ?> 
    253267<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

     
    17651765        } 
    17661766 
    17671767        /** 
     1768         * Retrieve Nginx formatted rewrite rules. 
     1769         * 
     1770         * @since 3.3.0 
     1771         * @access public 
     1772         * 
     1773         * @return string 
     1774         */ 
     1775        function nginx_url_rewrite_rules() { 
     1776                if ( ! $this->using_permalinks() ) 
     1777                        return ''; 
     1778 
     1779                $rules = "location / {\n"; 
     1780                $rules .= "\t" . 'try_files $uri $uri/ /index.php?$args;' . "\n"; 
     1781                $rules .= "}\n"; 
     1782 
     1783                $rules = apply_filters('nginx_rewrite_rules', $rules); 
     1784 
     1785                return $rules; 
     1786        } 
     1787 
     1788        /** 
    17681789         * Add a straight rewrite rule. 
    17691790         * 
    17701791         * Any value in the $after parameter that isn't 'bottom' will be placed at 
  • wp-includes/vars.php

     
    8383$is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false); 
    8484 
    8585/** 
     86 * Whether the server software is Nginx or something else 
     87 * @global bool $is_nginx 
     88 */ 
     89$is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false); 
     90 
     91/** 
    8692 * Whether the server software is IIS or something else 
    8793 * @global bool $is_IIS 
    8894 */