Fixing GeoDirectory + Polylang 404 Errors
A small compatibility fix for a rewrite-rule conflict between GeoDirectory Location Manager and Polylang that can cause GeoDirectory listing URLs to return 404 errors.
The Problem
When using GeoDirectory with Polylang, enabling Polylang’s Custom Post Types and Taxonomies module can cause GeoDirectory listing URLs to return 404 errors.
This can affect both the default language and translated URLs. The listings themselves remain available in the WordPress admin and can be created, translated, linked, and categorized normally. The problem occurs on the frontend, where WordPress needs to resolve the requested URL through its rewrite rules.
/listing/example-listing/ → 404/en/listing/example-listing/ → 404
What Causes the Conflict
The issue is related to the interaction between GeoDirectory Location Manager and Polylang’s multilingual rewrite rules.
Location Manager adds custom rewrite rules for location-based URLs, including cities, regions, and location-specific listings. When Polylang modifies the rewrite rules for translated custom post types, some of these GeoDirectory rules can no longer match the expected URLs correctly.
As a result, WordPress does not resolve the request to the corresponding GeoDirectory listing and returns a 404.
The Fix
The compatibility fix adds the required language-specific versions of the affected GeoDirectory rewrite rules.
- Works with the rewrite rules generated by GeoDirectory, Location Manager, and Polylang.
- Identifies the relevant GeoDirectory rules.
- Generates corresponding rules for the active Polylang languages.
- Adds the appropriate language context to those rules.
- Ensures the generated rules are evaluated before conflicting fallback rules.
The result is that GeoDirectory’s location-aware URLs can continue to work alongside Polylang’s language-prefixed URLs. The fix operates at the WordPress rewrite-rule level, without requiring additional listing queries or custom 404 handling on every request.
An Important Implementation Detail
Rewrite rules are slightly different from ordinary URLs because their query strings can contain WordPress rewrite variables such as $matches[1]. The language parameter needs to be added without encoding those variables.
$lang_query = (strpos($query, '?') !== false)
? $query . '&lang=' . $lang
: $query . '?lang=' . $lang;
Using functions that URL-encode the query can alter $matches[...] variables and prevent WordPress from correctly processing the rewrite rule.
Result
With the compatibility fix in place, the affected URLs can work normally across languages:
- Default-language listings
- Translated listings
- GeoDirectory location URLs
- Language-prefixed location URLs
The rules are handled through WordPress’s normal rewrite system rather than requiring a custom query or 404 interception during each request.
Open Source Plugin
The compatibility fix is available as a small open-source WordPress plugin.
Installation
- Download the plugin from GitHub.
- Upload it to
/wp-content/plugins/. - Activate the plugin.
- Go to Settings → Permalinks and click Save Changes to regenerate the rewrite rules.
Requirements
- WordPress 5.8+
- PHP 7.4+
- GeoDirectory
- GeoDirectory Location Manager
- Polylang
This fix is intended specifically for installations where GeoDirectory Location Manager and Polylang produce conflicting rewrite rules. Other plugins or custom rewrite configurations may require additional adjustments.