=== DevDome Redirect Manager ===
Contributors: DevDome.com Team
Tags: redirect, redirects, link rotator, geotargeting, 301 redirect
Requires at least: 5.6
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.2.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Redirect rules with link rotation, geo and device targeting, scheduling and 301/302/307/308/JavaScript/meta methods, plus per-rule statistics.

== Description ==

DevDome Redirect Manager lets you build redirect rules and point traffic wherever you need it: a single destination, a rotating list of URLs, a link already on the page, or the same path on another domain. Each rule has its own targeting, timing, schedule and statistics, and you can run as many rules side by side as you like.

Everything is configured from one screen (Tools language aside, no coding). Rules are independent: when a request comes in, the highest-priority running rule that matches handles it.

= What you can do =

* Redirect your entire site, only selected pages/posts/categories, a list of custom URL paths, or every 404 (not-found) page.
* Choose the redirect method per rule: JavaScript, 301 (permanent), 302 (temporary), 307, 308, or HTML meta refresh.
* Send traffic to a list of destination URLs, to a link/button already present on the page, or to the same path on a different domain.
* Rotate through multiple destinations in order (first to last), randomly, or with a weighted "click distribution" you control with a slider.
* Control how often a visitor is redirected: every visit, once per visitor, or again only after a delay you set (minutes/hours/days). Recognise a returning visitor by IP, or by IP + browser/device.
* Redirect only every N-th unique visitor.
* Open the destination in the same tab or a new tab (JavaScript method), with optional instant or randomized delays, and an optional "wait for a click" step.
* Target by device: desktop, mobile, tablet.
* Target by country with an optional geo filter (include only listed countries, or redirect everyone except listed countries).
* Schedule rules: always active, or a custom schedule with a run time, specific weekdays, and specific time windows.
* Decide what happens to visitors who do not match a rule: leave them on the page, or send them to a bypass link.
* Run multiple rules with drag-to-order priority; add, duplicate, delete, start and stop each one independently.
* See per-rule statistics, export every rule to a file, and import them back.

= Redirect Setup =

**What To Redirect**

* **Entire website** - the rule runs on every public page.
* **Selected existing URLs** - search your Categories, Pages and Posts and add them with a live picker (chips with per-item hit counts; drag to set priority for the "found" mode).
* **Custom URLs** - type exact paths, one per line (for example `/blog/` or `/blog/best-headphones/`), whether the page exists or not. A trailing slash matches that page and everything under it.
* **All 404's** - the rule runs on every not-found page (handy for catching dead links).

**Redirect Method** - JavaScript Redirect, 301 Permanent, 302 Temporary, 307 Temporary, 308 Permanent, or Meta Refresh. New-tab opening and client-side delays are available with the JavaScript method only; server and meta methods always open in the same tab.

**Where To Send Traffic**

* **To provided links** - enter one or more destination URLs and rotate through them.
* **To links or buttons on the page** - enter a fragment (for example `amazon.com`) and the rule redirects to the matching link/button already on the page. You can target the N-th match.
* **To same path on another domain** - keep the visitor's path and query and send it to another domain (for example `yoursite.com/post/123` becomes `otherdomain.com/post/123`).

**Link rotation** (provided links) - First to last, Random, or Weighted distribution. The weighted mode adds a Click Distribution slider (first link gets most, even split, or last link gets most) with a live preview. "Repeat List" starts again from the first URL once the list is exhausted.

**How often to redirect** - Every visit, Once per visitor, or After a delay. When it is not "every visit", you choose how a returning visitor is identified (IP address, or IP + browser/device), can redirect only every N-th unique visitor, and (for the delay option) set the gap before the same visitor is redirected again.

= Open Link Settings =

* **Open Link In** - Same Tab or New Tab (New Tab requires the JavaScript method).
* **Same Tab Link Delay** - instant, or a random delay (seconds) within a range.
* **Redirect On Click** - wait for the visitor to click/tap anywhere before redirecting, instead of redirecting automatically.
* **After Click Delay** - after the click, wait a random time (up to 4 seconds) before redirecting.
* **New Tab Link Delay** - instant or a random delay before the new tab is armed. A new tab can only open on a real click, so the destination opens on the visitor's next click after the delay (browsers block tabs that open by themselves).

= Geo Filter Settings =

* **Test geo service** - confirm the geo service is reachable from your server before you rely on it.
* **Geo Filtering** - turn the country filter on or off (off by default).
* **Filter mode** - redirect only the listed countries, or redirect everyone except the listed countries. If the visitor's country cannot be resolved, an "except listed" (blacklist) rule does not redirect that visitor (it fails safe).
* **Site Behind Proxy / CDN** - if your site sits behind Cloudflare or another proxy, enable "Trust forwarded IP headers" so the real visitor IP is used for country lookup. "Detect automatically" inspects the current request and ticks the box for you.

See the External services section below for what the geo filter sends and where.

= Optional Settings =

* **Devices to Redirect** - redirect only the checked device types (Desktop / Mobile / Tablet); other devices follow your "Not Redirected Visitors" setting.
* **Purge Page Cache On Save** - clear cached copies of the pages a rule targets when you save/run it, so the redirect takes effect immediately. Works with WP Rocket, LiteSpeed Cache, W3 Total Cache, WP Super Cache, WP Fastest Cache, SiteGround Optimizer, WP-Optimize, Cache Enabler, Hummingbird and Breeze.
* **Not Redirected Visitors** - Leave On Page (do nothing), or Send To Bypass Link (send non-matching visitors to a URL you choose).
* **Schedule Mode** - Always Active, or Custom Schedule with a run time, selected weekdays, and up to three specific time windows.

= Rules, run state and statistics =

* Add, duplicate, delete and reorder rules; each rule has its own nickname and priority.
* Start a rule with "Save & Run", stop it with "Stop"; a live status shows Running/Stopped, run time and time left.
* "Save Settings" saves without changing the run state; "Return to Default" resets the current rule's settings.
* Each rule keeps its own statistics (visitors, page views, unique users, unique IPs, redirects, bypassed visitors, per-device and per-country counts, and per-source/destination breakdowns), with a time-range filter. "Reset Stats" clears the current rule's counters and rotation position.
* **Export** downloads all rules and their configuration to a JSON file (no stats, no run state). **Import** replaces every rule on the site with the rules from a file (imported rules arrive stopped).

== Installation ==

1. Upload the plugin to `/wp-content/plugins/` (or install it from the Plugins screen) and activate it.
2. Open **Tools -> DevDome Redirect Manager** (the DevDome Tools menu).
3. Pick what to redirect, choose a redirect method and where to send traffic, then set any targeting, timing and schedule you need.
4. Click **Save & Run** to start the rule. Use **Save Settings** to save changes without changing the run state.

No account is required for the redirect features. The geo filter is optional and off by default.

== Frequently Asked Questions ==

= Does the redirect work without JavaScript? =
Yes. Choose 301, 302, 307, 308 or Meta Refresh for a redirect that does not need JavaScript. The JavaScript method is only needed for new-tab opening, "wait for a click", and client-side delays.

= My redirect does not fire immediately after saving. Why? =
A caching plugin or server cache may still be serving a stored copy of the page. Keep "Purge Page Cache On Save" enabled so the targeted pages are cleared when you save or run the rule.

= Can I run more than one rule at the same time? =
Yes. Rules are independent and ordered by priority. For a given request, the highest-priority running rule that matches handles it.

= What does "Once per visitor" mean? =
The visitor is redirected the first time only, and then left on the page on later visits, until you reset the rule's stats. Choose "After a delay" instead if you want the redirect to become available again after a set time. A visitor is identified by IP, or by IP + browser/device.

= Why is "New Tab" greyed out / reverting to "Same Tab"? =
New-tab opening needs the JavaScript method. With a 301/302/307/308 or Meta Refresh method the redirect always happens in the same tab.

= Does the geo filter send any data off my site? =
Only when you enable Geo Filtering. See the External services section for exactly what is sent and where. With Geo Filtering off (the default), the plugin makes no external requests.

= How do I move my rules to another site? =
Use Export to download a JSON file of all rules, then Import on the other site. Imported rules arrive stopped, so you can review them before starting.

== External services ==

This plugin connects to the DevDome geo-resolution service only when you use the optional **Geo Filter** feature. With Geo Filtering turned off (the default), the plugin does not contact any external service.

What it is used for: turning a visitor's IP address into a two-letter country code so a rule can include or exclude countries.

What is sent and when:

* When a rule with Geo Filtering enabled handles a front-end request, the visitor's IP address is sent to `https://api.devdome.com/geo-resolve` to look up a country code. Results are cached so the same IP is not looked up repeatedly.
* The **Test geo service** button requests `https://api.devdome.com/geo-resolve/health` to check availability. No visitor data is sent.
* The **Detect automatically** (proxy/CDN) button runs locally on your server and sends no data to any external service.

Service provider: DevDome. Terms: https://devdome.com/terms . Privacy policy: https://devdome.com/privacy .

== Screenshots ==

1. Redirect Setup - what to redirect, redirect method, and where to send traffic.
2. Link rotation with the weighted Click Distribution slider.
3. Open Link Settings - same tab / new tab, delays and "wait for a click".
4. Geo Filter Settings - country include/exclude and proxy detection.
5. Optional Settings - devices, cache purge, bypass link and schedule.
6. Rules list with per-rule statistics, run/stop and import/export.

== Changelog ==

= 1.1.5 =
* Fixed: full-URL and bare-domain matches now ignore a leading `www.`, so a www / non-www difference no longer stops a redirect.
* Fixed: Custom URLs / Selected pages now match correctly on WordPress installs in a subdirectory.
* Fixed: "Once per visitor" now reliably redirects a visitor only once (it was redirecting on every visit).
* Fixed: link rotation (sequential/random) is now tracked per rule, so rules that share a visitor no longer interfere with each other.
* Fixed: with the geo "redirect all except listed countries" mode, a visitor whose country cannot be resolved is no longer redirected (fails safe).
* Fixed: new-tab opening with an after-click delay is no longer blocked by the browser pop-up blocker.
* Fixed: "Reset Stats" now also restarts the rule's rotation position.
* Improved: more accurate unique-visitor and redirect counting behind shared IP addresses.
* Improved: bounded internal visitor history and switched the settings store to an upsert to avoid growth and write contention under traffic.
* Hardened: rule Run/Stop now requires a valid security token, the bypass URL is validated, and activation no longer clears the plugin's own saved options.

== Upgrade Notice ==

= 1.1.5 =
Recommended update: fixes www/non-www and subdirectory matching, "once per visitor", per-rule link rotation, geo fail-safe and new-tab pop-up handling, plus accuracy and reliability improvements.
