函数文档

got_url_rewrite()

💡 云策文档标注

概述

got_url_rewrite() 函数用于检测服务器是否支持 URL 重写,主要检查 Apache 的 mod_rewrite、IIS 7.0+ 的永久链接支持以及 nginx 和 Caddy 服务器。

关键要点

  • 函数返回布尔值,表示服务器是否支持 URL 重写。
  • 检测逻辑包括 got_mod_rewrite()、全局变量 $is_nginx 和 $is_caddy,以及 iis7_supports_permalinks() 函数。
  • 可通过 apply_filters('got_url_rewrite', $got_url_rewrite) Hook 过滤返回值。
  • 自 WordPress 3.7.0 版本引入。

📄 原文内容

Returns whether the server supports URL rewriting.

Description

Detects Apache’s mod_rewrite, IIS 7.0+ permalink support, and nginx.

Return

bool Whether the server supports URL rewriting.

Source

function got_url_rewrite() {
	$got_url_rewrite = ( got_mod_rewrite() || $GLOBALS['is_nginx'] || $GLOBALS['is_caddy'] || iis7_supports_permalinks() );

	/**
	 * Filters 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 );
}

Hooks

apply_filters( ‘got_url_rewrite’, bool $got_url_rewrite )

Filters whether URL rewriting is available.

Changelog

Version Description
3.7.0 Introduced.