Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk10 min

How to Exclude a Folder From WordPress Permalinks (Without Breaking Your URLs)

“Exclude a folder” can mean three different WordPress routing tasks. This guide shows the correct fix for custom post types, category and tag bases, and real directories outside WordPress.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

There is no single WordPress setting called “exclude a folder.” The correct fix depends on what you mean: removing a prefix from a custom post type, changing a category or tag base, or keeping a real directory or separate application outside WordPress. Use the WordPress permalink screen for supported naming changes, registration code for a custom post type, and Apache or Nginx routing for a physical folder. After any change, regenerate rewrite rules and preserve old URLs with redirects.

Identify which kind of folder you want to exclude

WordPress uses the word “folder” loosely because URL paths look like directories. A path such as /library/ might be a custom post type slug, a taxonomy base, a normal WordPress page, or an actual directory on disk. Those cases are handled at different layers.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
What you are trying to change Where to change it Can the standard screen do it?
Remove a global front prefix from one custom post type register_post_type() rewrite arguments Not precisely; use registration code
Rename the category or tag prefix Settings > Permalinks, Optional fields Yes, for renaming
Remove a category or tag prefix completely Custom rewrite code or a maintained plugin No; core fields do not remove it
Keep a real directory or another application outside WordPress Apache or Nginx request routing No
Disable or redesign every rewrite rule for a path WordPress rewrite APIs, plugin, and possibly the server No; requires testing for collisions

Decide which row matches your requirement before editing anything. Changing the wrong layer can leave the URL unchanged, create 404 errors, or send requests to the wrong application.

How WordPress decides which URL handles a request

A pretty permalink passes through several decisions. The web server receives the request first. Apache or Nginx may serve an existing file or directory, pass a request to another application, or send an unmatched path to WordPress’s index.php. WordPress then evaluates its stored rewrite rules and resolves the path to a post, page, taxonomy archive, feed, search request, or other query.

The rules are influenced by the structure selected at Settings > Permalinks, the rewrite arguments used when post types and taxonomies are registered, and the rules generated by WP_Rewrite. A PHP registration change does not automatically rewrite the rules already stored for the site. That is why a correct code change can appear ineffective until the rules are flushed.

WordPress documentation defines permalinks as the permanent URLs of posts, pages, categories, and other archive pages. Treat a change as a URL migration, not merely a cosmetic edit: links, canonical URLs, feeds, sitemaps, caches, bookmarks, and external references may all depend on the old path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Remove a global prefix from one custom post type

This is the usual answer to a question such as “How do I remove /blog/ from my books?” Suppose the site-wide structure or a theme setting places content under a front base, but the book post type should use /library/ directly. Define an explicit rewrite slug and set with_front to false.

Register the post type with its own slug

register_post_type('book', [
    'public' => true,
    'has_archive' => true,
    'rewrite' => [
        'slug' => 'library',
        'with_front' => false,
    ],
]);

The slug becomes the path segment for individual books and, when enabled, the archive. with_front => false tells WordPress not to prepend the site’s global front base. If the front base is blog, the resulting URL is intended to be /library/example-book/, not /blog/library/example-book/.

Apply the change safely

  1. Make the registration change in the plugin or theme code that owns the post type. A plugin is preferable when the content must survive a theme switch.
  2. Check that no page, taxonomy, other post type, or physical directory already uses library. URL resolution is shared, so a collision can make one object unreachable.
  3. Deploy the code to staging first and open an individual item, the archive, pagination, feeds, and any registered taxonomies.
  4. In the WordPress dashboard, go to Settings > Permalinks and click Save Changes once. You do not need to alter the selected structure; saving causes WordPress to regenerate its rules.
  5. Test the previous URL and the new URL. If the old address was public, add a permanent redirect from the old path to the new canonical path.

Flush rules on plugin activation, not every request

Flushing on every page load is expensive and can create race conditions. A plugin should flush when it is activated or deactivated, after the post type has been registered:

function my_register_book_type() {
    register_post_type('book', [
        'public' => true,
        'has_archive' => true,
        'rewrite' => [
            'slug' => 'library',
            'with_front' => false,
        ],
    ]);
}
add_action('init', 'my_register_book_type');

function my_activate_books() {
    my_register_book_type();
    flush_rewrite_rules();
}
register_activation_hook(__FILE__, 'my_activate_books');

function my_deactivate_books() {
    flush_rewrite_rules();
}
register_deactivation_hook(__FILE__, 'my_deactivate_books');

If the registration lives in a theme, use the dashboard save operation after switching or updating the theme rather than putting a flush call on init.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check common custom post type collisions

  • Page collision: a page named library can compete with the archive base.
  • Taxonomy collision: a taxonomy rewrite using the same slug can capture archive requests.
  • Singular/archive ambiguity: an archive base and a single-item slug should be planned together, especially when hierarchical paths are involved.
  • Existing links: changing the slug does not update links stored in old articles, menus, feeds, or external sites.

Rename a category or tag base

Category and tag bases are different from a custom post type prefix. WordPress’s standard permalink screen lets you rename them, but the documented core behavior does not let you remove them entirely through those fields. For example, you can change the category base from category to topics, producing URLs such as /topics/security/.

Change the base in the dashboard

  1. Open Settings > Permalinks.
  2. Scroll to the Optional section.
  3. Enter the desired value in Category base and/or Tag base. Use a short, URL-safe word; do not include a leading slash.
  4. Click Save Changes.
  5. Open an existing category and tag archive, a paginated archive, and a feed to verify that each resolves.

WordPress documentation states that the default values are category and tag; they can be changed but cannot be removed from URLs altogether in the standard fields.

If you truly need base-less taxonomy URLs

A URL such as /security/ could be a category, a page, a post, or a custom taxonomy term. Removing the distinguishing base therefore increases ambiguity. You need custom rewrite rules or a maintained plugin that changes taxonomy queries and generates matching links.

  • Map term archives before generic page and post rules, or valid terms may resolve to the wrong object.
  • Handle feeds, pagination, canonical redirects, REST links, sitemaps, and term editing screens.
  • Test a term whose name matches a page, post, author, date archive, or search endpoint.
  • Keep a rollback plan because a plugin update, theme change, or new page can alter the collision set.

Do not edit only the visible links. If the rewrite query is not changed as well, the site may display base-less URLs that return 404 responses.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep a real directory outside WordPress

If /downloads/ is a directory on the server, or a separate application owns /app/, a WordPress permalink field cannot exclude it. The web server must route that path before its catch-all rule forwards requests to WordPress.

Apache

Apache configurations vary by virtual host and hosting plan. The principle is to define the directory or application mapping before the general WordPress rule. Existing files and directories are commonly allowed through with conditions similar to these:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule . /index.php [L]

This pattern lets Apache serve a real directory instead of sending it to index.php. If the directory is not physically inside the document root, use an appropriate Alias or virtual-host mapping and grant the required filesystem permissions. If a separate application handles the path, place its proxy or rewrite rule before the WordPress catch-all. Back up the configuration and validate it before reloading Apache.

Nginx

Nginx typically uses a more specific location block before the general WordPress location:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
location ^~ /downloads/ {
    try_files $uri $uri/ =404;
}

location / {
    try_files $uri $uri/ /index.php?$args;
}

The first block keeps requests under /downloads/ in the filesystem. For another application, replace try_files with the appropriate upstream proxy configuration. Exact document-root, PHP, alias, and permission settings differ by server, so apply the example to the site’s existing configuration rather than pasting it blindly.

Verify server-level exclusions

  1. Request a known file in the reserved directory and confirm the expected server or application returns it.
  2. Request a missing file under that directory and confirm it does not fall through to a WordPress 404 or front controller unless that is intentional.
  3. Request a normal WordPress page and a post to ensure the catch-all still works.
  4. Check trailing-slash behavior, HTTPS redirects, cache rules, access controls, and static-file content types.
  5. Review logs after deployment. A 404, redirect loop, or unexpected PHP execution usually indicates rule order, permissions, or an alias mismatch.

Use rewrite APIs or a plugin for advanced behavior

WP_Rewrite generates the rule sets used for posts, taxonomies, searches, authors, feeds, and other endpoints. Filters can alter individual rule groups, but this is an application-level change with site-wide consequences. A plugin can package the logic and provide link filters, migration tools, and an interface, reducing the amount of custom code you maintain.

When custom code is justified

  • The requirement is specific to a post type or taxonomy and cannot be expressed by its registration arguments.
  • You can define unambiguous precedence for pages, posts, terms, feeds, and pagination.
  • You have staging tests and a documented rollback.
  • The code owner will maintain it when WordPress, the active theme, or another URL plugin changes.

When a plugin is safer

Choose a maintained plugin when you need a repeatable configuration, a supported migration path, or compatibility handling that would be costly to write. Check its update history, supported WordPress versions, issue reports, and interaction with the active theme and other permalink customizations. A plugin is still code running on the site; test it on staging and keep database and filesystem backups.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Regenerate rewrite rules correctly

Dashboard method

The simplest method is Settings > Permalinks > Save Changes. If the server allows WordPress to write .htaccess, WordPress updates it automatically. If the file is not writable, the screen displays rules for manual installation. Copy those rules exactly into the appropriate server configuration, then reload the server as required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WP-CLI method

On a site managed with WP-CLI, the rewrite structure command updates the stored structure:

wp rewrite structure '/%postname%/' --hard

The --hard option also updates .htaccess when the installation is configured for that operation. Category and tag bases can be supplied with the command’s corresponding options when changing the structure from the command line. Run commands as the site’s correct filesystem user, back up configuration first, and inspect the resulting rules rather than assuming the command can modify a managed hosting proxy.

Do not flush on every request

Rewrite flushing rebuilds rules and can be costly on a busy site. Run it only after a relevant registration or configuration change, during deployment, or through an activation/deactivation hook.

Plan redirects and the SEO migration

Any public URL change should have a redirect map. Record the old path, the new path, the object type, and the date of the change. Redirect each old URL to its closest new equivalent with a permanent redirect; do not send every old address to the home page.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Update internal links, navigation, breadcrumbs, feeds, XML sitemaps, canonical tags, and structured data generated by your theme or plugins.
  • Clear page, object, CDN, and server caches after the rules are deployed.
  • Check both logged-in and anonymous requests, because caching or security layers can route them differently.
  • Monitor access and error logs for old paths, redirect loops, and unexpected 404 responses.
  • Keep the redirect rules for as long as external links and bookmarks can reasonably be expected to use the old structure.

Before changing a high-traffic structure, export the current rewrite configuration and database backup, and test the migration on a staging copy with representative pages, posts, terms, feeds, and media paths.

Troubleshoot the most common failures

Symptom Likely cause What to check
The new custom post type URL is still under the global prefix with_front is missing or true, or stale rules remain Confirm the registration argument, save Permalinks, and test without a cached response
Every changed URL returns 404 Rewrite rules were not regenerated or server rewrites are disabled Save Permalinks, inspect .htaccess or Nginx configuration, and review server logs
A real folder opens a WordPress page The server catch-all runs before the folder or alias rule Move the specific rule earlier and verify filesystem or upstream mapping
A category base change works for archives but not feeds Feed or pagination rules were not tested or are cached Open archive feeds and paginated URLs, then clear relevant caches
A page and taxonomy term produce inconsistent results Base-less URLs collide Rename one object or add explicit precedence; avoid ambiguous slugs
Saving Permalinks shows rules but does not write them .htaccess is not writable or the host controls server configuration Install the displayed rules manually or ask the host to update the virtual-host configuration
Redirects loop after deployment Conflicting HTTPS, trailing-slash, proxy, or old-path rules Trace one request through each layer and remove duplicate redirects

Choose the least risky method

Method Best for Main risk Rollback
Permalinks screen Supported post structures and renaming category/tag bases Cannot remove category/tag bases; may require manual server write Restore the previous fields and save
Post type registration Giving one custom post type an explicit slug and excluding the front base Slug collisions and forgotten rule flush Restore the old arguments and redirects
Maintained plugin Complex taxonomy or post-type URL rules Dependency, compatibility, and update risk Disable after restoring redirects and rules
Apache or Nginx configuration Physical directories and separate applications Can affect every application on the host Revert the versioned server configuration
Custom WP_Rewrite filters Specialized routing not covered by registration arguments High collision and maintenance burden Remove filters, flush rules, and restore URL mappings

Pre-deployment checklist

  • Identify whether the target is a post type, taxonomy base, physical directory, or separate application.
  • List every existing page, post type, taxonomy, feed, endpoint, and directory that could share the proposed slug.
  • Back up the database and server configuration.
  • Test the change on staging with singular URLs, archives, pagination, feeds, search, and redirects.
  • Deploy the registration or server rule before flushing rewrite rules.
  • Save Settings > Permalinks or run the appropriate WP-CLI command once.
  • Verify old URLs, new URLs, canonical output, sitemaps, caches, and logs.
  • Keep a redirect map and a rollback copy of the previous configuration.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.