Title: PathGuard Redirects
Author: MD. Samrat Hossen
Published: <strong>2026 年 5 月 22 日</strong>
Last modified: 2026 年 5 月 22 日

---

搜索插件

![](https://ps.w.org/pathguard-redirects/assets/banner-772x250.png?rev=3543071)

![](https://ps.w.org/pathguard-redirects/assets/icon-256x256.png?rev=3543071)

# PathGuard Redirects

 作者：[MD. Samrat Hossen](https://profiles.wordpress.org/emily50/)

[下载](https://downloads.wordpress.org/plugin/pathguard-redirects.1.0.0.zip)

 * [详情](https://cn.wordpress.org/plugins/pathguard-redirects/#description)
 * [评价](https://cn.wordpress.org/plugins/pathguard-redirects/#reviews)
 *  [安装](https://cn.wordpress.org/plugins/pathguard-redirects/#installation)
 * [开发进展](https://cn.wordpress.org/plugins/pathguard-redirects/#developers)

 [支持](https://wordpress.org/support/plugin/pathguard-redirects/)

## 描述

URL Blocker is a lightweight, developer-friendly plugin that lets site administrators
block any relative URL on their WordPress site and control exactly what happens 
when a visitor tries to access it.

**How it works**

Add the relative paths you want to block (one per line) and choose what should happen
when someone visits them:

 * **Custom URL redirect** — send visitors to any destination URL with a 302 redirect.
 * **404 Not Found** — serve your theme’s native 404 page with a proper HTTP 404
   status header (no redirect, the URL stays the same).

**Key features**

 * Block any number of relative paths (e.g. `/secret-page/`, `/members-only/`).
 * Choose the redirect action per-site: custom URL or 404 page.
 * **Exclude Admins** — logged-in administrators are bypassed by default so they
   always have access. The option can be unchecked to restrict admins too.
 * One-click access via the **Settings** link on the Plugins list page.
 * All plugin data is removed from the database automatically when the plugin is
   deactivated.
 * Paths matched with and without trailing slash — `/secret-page` and `/secret-page/`
   both work.
 * URL-encoded paths are decoded before matching, preventing bypass attempts like`/%
   73ecret-page/`.

**Security**

 * CSRF protection on every save using WordPress nonces.
 * Strict capability check (`manage_options`) before processing any form data.
 * All input is sanitised (`sanitize_textarea_field`, `esc_url_raw`, `sanitize_key`).
 * All output is escaped (`esc_textarea`, `esc_attr`, `esc_html_e`).
 * Uses `wp_safe_redirect` to prevent open-redirect abuse.

## 安装

 1. Upload the `pathguard-redirects` folder to `/wp-content/plugins/`.
 2. Activate the plugin through the **Plugins** screen in WordPress.
 3. Go to **Settings  URL Blocker** (or click the **Settings** link on the Plugins 
    page).
 4. Enter the relative URLs you want to block, choose a redirect action, and click **
    Save Settings**.

## 常见问题

### What URL format should I use in the blocked URLs list?

Enter relative paths starting with `/`, one per line. Example:

    ```
    /secret-page/
    /members-only/
    /private-area/
    ```

Do not include the domain name. Paths are matched with or without a trailing slash,
so `/secret-page` and `/secret-page/` are treated as the same rule.

### Will administrators be blocked?

No — by default the **Exclude Admins** option is enabled, which means logged-in 
users with the `manage_options` capability can always access blocked URLs. You can
uncheck this option to apply blocking to administrators as well.

### What is the difference between the two redirect actions?

 * **Custom URL (302 redirect)** — the visitor’s browser is redirected to the URL
   you specify. The blocked URL disappears from the address bar.
 * **Not Found (404 page)** — the browser stays on the blocked URL but receives 
   an HTTP 404 status and sees your theme’s 404 template. No redirect occurs.

### What happens if I choose “Custom URL” but leave the destination field blank?

The plugin falls back to serving the 404 page so the blocked URL is never accidentally
left accessible.

### Does this plugin affect REST API or admin requests?

No. The block logic runs on the `template_redirect` hook which only fires for standard
frontend page requests. REST API, WP-CLI, and admin requests are unaffected.

### Will my settings be lost if I deactivate the plugin?

Yes. The plugin removes all its stored options from the database on deactivation.
This keeps your database clean. If you need to keep your settings, do not deactivate—
simply disable blocking by leaving the blocked URLs list empty.

### Does the plugin block query strings?

No. Only the path portion of the URL is compared (e.g. `/secret-page/`). Query strings
like `?preview=true` are ignored, which means `/secret-page/?anything=value` is 
still blocked by the rule `/secret-page/`.

## 评价

此插件暂无评价。

## 贡献者及开发者

「PathGuard Redirects」是开源软件。 以下人员对此插件做出了贡献。

贡献者

 *   [ MD. Samrat Hossen ](https://profiles.wordpress.org/emily50/)

[帮助将「PathGuard Redirects」翻译成简体中文。](https://translate.wordpress.org/projects/wp-plugins/pathguard-redirects)

### 对开发感兴趣吗?

您可以[浏览代码](https://plugins.trac.wordpress.org/browser/pathguard-redirects/)，
查看[SVN仓库](https://plugins.svn.wordpress.org/pathguard-redirects/)，或通过[RSS](https://plugins.trac.wordpress.org/log/pathguard-redirects/?limit=100&mode=stop_on_copy&format=rss)
订阅[开发日志](https://plugins.trac.wordpress.org/log/pathguard-redirects/)。

## 更新日志

#### 1.0.0

 * Initial release.
 * Block relative URLs with per-line textarea input.
 * Redirect action: Custom URL (302) or 404 page.
 * Exclude Admins option, pre-enabled on activation.
 * Settings link on the Plugins list page.
 * Automatic database cleanup on deactivation.
 * URL-encoding bypass protection via `rawurldecode()`.
 * CSRF, capability, and sanitisation hardening.

## 额外信息

 *  版本 **1.0.0**
 *  最后更新：**2 周前**
 *  活跃安装数量 **不到10**
 *  WordPress 版本 ** 5.8 或更高版本 **
 *  已测试的最高版本为 **6.9.4**
 *  PHP 版本 ** 7.4 或更高版本 **
 *  语言
 * [English (US)](https://wordpress.org/plugins/pathguard-redirects/)
 * 标签
 * [access-control](https://cn.wordpress.org/plugins/tags/access-control/)[redirect](https://cn.wordpress.org/plugins/tags/redirect/)
   [security](https://cn.wordpress.org/plugins/tags/security/)
 *  [高级视图](https://cn.wordpress.org/plugins/pathguard-redirects/advanced/)

## 评级

尚未提交反馈。

[Your review](https://wordpress.org/support/plugin/pathguard-redirects/reviews/#new-post)

[查看全部评论](https://wordpress.org/support/plugin/pathguard-redirects/reviews/)

## 贡献者

 *   [ MD. Samrat Hossen ](https://profiles.wordpress.org/emily50/)

## 支持

有话要说吗？是否需要帮助？

 [查看支持论坛](https://wordpress.org/support/plugin/pathguard-redirects/)