Home » Custom Posts and Fields » Rewrite Rules

Rewrite Rules

Benefits of Using Rewrite Rules in QuickBuildWP

Rewrite rules in QuickBuildWP allow you to customize your URL structure for better SEO, readability, and dynamic content filtering. Instead of relying on WordPress’s default query string format, you can create clean, user-friendly URLs.

1. SEO-Friendly & Readable URLs

Before (Default WordPress URL)

https://www.example.com/?category=financial-institutions&tag=artisan

After (Custom QuickBuildWP URL)

https://www.example.com/financial-institutions/artisan
Benefits:
  • More readable and user-friendly.
  • Boosts SEO as URLs with keywords rank better in search engines.
  • Easier to share and remember.

2. Flexible URL Structures

With QuickBuildWP, you can define your own custom patterns for dynamic content filtering.

Example: Displaying Content Based on Category & Tag

If you want to filter posts based on category and tag, you can set up a rewrite rule like:
https://www.example.com/financial-institutions/artisan
Here’s how it works:
  • financial-institutions → Category
  • artisan → Tag
  • WordPress will dynamically fetch and display posts that match both.
Benefits:
  • Custom rules allow more flexible content filtering.
  • You control how URLs structure your data.
  • Easier for users to navigate content.

3. Avoids Query String URLs

By using rewrite rules, you avoid using ugly query strings (?category=financial-institutions&tag=artisan), making URLs:
  • More professional-looking.
  • Easier to cache (better performance).
  • Compatible with modern web standards.

How to Setup Rewrite Rules in QuickBuildWP

Overview

QuickBuildWP allows you to define custom rewrite rules to modify how URLs are structured and handled in your WordPress site. These rules are useful for creating SEO-friendly URLs and managing custom content structures dynamically.

Step 1: Add a Rewrite Rule

To set up a custom rewrite rule, follow these steps:
  1. Go to Dashboard → Field Groups.
  2. Edit an existing field group or create a new one.
  3. Find the "Rewrite Rules" input field and enter your desired pattern.

Fields to Configure

Field Example Value Description
Pattern ^([^/]+)/([^/]+)/?$ Defines the URL structure to match.
Query Vars (JSON Format) {"category":1,"tag":2} Maps URL parameters to WordPress query variables.
Exclude CPT Default Unchecked Excludes CPTs (Custom Post Types) from conflicts.

Step 2: Understanding Exclude CPT Option

By enabling the "Exclude CPT" option, you can prevent conflicts between default WordPress URLs and custom rewrite rules.

Example Conflict Issue

Without Exclude CPT, both of these URLs may conflict because they share the same pattern:
  1. WordPress Default URL:
    https://www.example.com/listing/artisan-bakers/
  2. Custom Pattern URL (Rewrite Rule Applied):
    https://www.example.com/financial-institutions/artisan/
To avoid conflicts, QuickBuildWP dynamically modifies the pattern if "Exclude CPT" is enabled. If you are using a string in a pattern e.g. listing/([^/]+)/([^/]+)/?$, there is no need to check this checkbox.

Step 3: Apply the Rewrite Rule

Once you've specified the pattern and query variables, follow these steps:
  1. Go to Dashboard → QuickBuildWP.
  2. Click "Update Rewrite Rules" to save and apply your changes.
Behind the Scenes:
  • QuickBuildWP registers the rewrite rules.
  • WordPress flushes the rewrite cache to ensure new rules take effect.
  • Your URLs now follow the new custom structure.

Step 4: Use the Correct Template

Once a rewrite rule is applied, QuickBuildWP will automatically map it to the archive.php template.

Template Naming Convention

  • If the field group name is listing, the system will use the template:
    listing-archive.php
Similarly, for a field group named news, QuickBuildWP will expect:
news-archive.php

Troubleshooting Rewrite Rules in QuickBuildWP

If your rewrite rules are not working, follow these troubleshooting steps to resolve common issues.

Flush Rewrite Rules Manually

Sometimes, WordPress does not recognize new rewrite rules immediately. To force WordPress to update them:
  1. Go to Dashboard → Settings → Permalinks.
  2. Click the "Save Changes" button, even if you don't change anything.
  3. Check your URLs again.
Why This Works?
  • WordPress rebuilds its internal URL structure.
  • Ensures that new rewrite rules take effect.