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
This commit is contained in:
parent
1de240d5a2
commit
d3b89d43fc
|
@ -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
|
* @since 2.0.0
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function got_mod_rewrite() {
|
function got_mod_rewrite() {
|
||||||
$got_rewrite = apache_mod_loaded('mod_rewrite', true);
|
$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);
|
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}}
|
* {@internal Missing Short Description}}
|
||||||
*
|
*
|
||||||
|
|
|
@ -75,7 +75,7 @@ $home_path = get_home_path();
|
||||||
$iis7_permalinks = iis7_supports_permalinks();
|
$iis7_permalinks = iis7_supports_permalinks();
|
||||||
|
|
||||||
$prefix = $blog_prefix = '';
|
$prefix = $blog_prefix = '';
|
||||||
if ( ! got_mod_rewrite() && ! $iis7_permalinks )
|
if ( ! got_url_rewrite() )
|
||||||
$prefix = '/index.php';
|
$prefix = '/index.php';
|
||||||
if ( is_multisite() && !is_subdomain_install() && is_main_site() )
|
if ( is_multisite() && !is_subdomain_install() && is_main_site() )
|
||||||
$blog_prefix = '/blog';
|
$blog_prefix = '/blog';
|
||||||
|
@ -126,6 +126,8 @@ if ( $iis7_permalinks ) {
|
||||||
$writable = true;
|
$writable = true;
|
||||||
else
|
else
|
||||||
$writable = false;
|
$writable = false;
|
||||||
|
} elseif ( $is_nginx ) {
|
||||||
|
$writable = false;
|
||||||
} else {
|
} else {
|
||||||
if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') )
|
if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') )
|
||||||
$writable = true;
|
$writable = true;
|
||||||
|
@ -152,6 +154,8 @@ if ( ! is_multisite() ) {
|
||||||
_e('Permalink structure updated. Remove write access on web.config file now!');
|
_e('Permalink structure updated. Remove write access on web.config file now!');
|
||||||
else
|
else
|
||||||
_e('Permalink structure updated.');
|
_e('Permalink structure updated.');
|
||||||
|
} elseif ( $is_nginx ) {
|
||||||
|
_e('Permalink structure updated.');
|
||||||
} else {
|
} else {
|
||||||
if ( $permalink_structure && ! $usingpi && ! $writable )
|
if ( $permalink_structure && ! $usingpi && ! $writable )
|
||||||
_e('You should update your .htaccess now.');
|
_e('You should update your .htaccess now.');
|
||||||
|
@ -226,9 +230,9 @@ $structures = array(
|
||||||
|
|
||||||
<h3 class="title"><?php _e('Optional'); ?></h3>
|
<h3 class="title"><?php _e('Optional'); ?></h3>
|
||||||
<?php
|
<?php
|
||||||
$suffix = '';
|
$suffix = $prefix;
|
||||||
if ( ! $is_apache && ! $iis7_permalinks )
|
if ( $suffix )
|
||||||
$suffix = $wp_rewrite->index . '/';
|
$suffix = ltrim( $suffix, '/' ) . '/';
|
||||||
?>
|
?>
|
||||||
<p><?php
|
<p><?php
|
||||||
/* translators: %s is a placeholder that must come at the start of the URL path. */
|
/* translators: %s is a placeholder that must come at the start of the URL path. */
|
||||||
|
@ -269,7 +273,7 @@ printf( __('If you like, you may enter custom structures for your category and t
|
||||||
<p><?php _e('If you temporarily make your site’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>
|
<p><?php _e('If you temporarily make your site’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>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php else :
|
<?php elseif ( ! $is_nginx ) :
|
||||||
if ( $permalink_structure && ! $usingpi && ! $writable ) : ?>
|
if ( $permalink_structure && ! $usingpi && ! $writable ) : ?>
|
||||||
<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’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>
|
<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’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>
|
||||||
<form action="options-permalink.php" method="post">
|
<form action="options-permalink.php" method="post">
|
||||||
|
|
|
@ -86,6 +86,12 @@ $is_IE = ( $is_macIE || $is_winIE );
|
||||||
*/
|
*/
|
||||||
$is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);
|
$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
|
* Whether the server software is IIS or something else
|
||||||
* @global bool $is_IIS
|
* @global bool $is_IIS
|
||||||
|
|
Loading…
Reference in New Issue