Clean Up Messy URLs: Encoding and Consistency Fixer
One page, many URLs: with brackets, without brackets, with %20, with +, with capital letters, with a slash at the end. Google may treat each one as a different page. This prompt finds your messy URL patterns, picks one clean version and gives you the rules to use it everywhere.
Example input
This is exactly what we gave the model. You replace it with your own details.
- Website: https://shop.example.com (camera and lens store) - Platform: Custom PHP store on Apache - Where messy URLs come from: Filter parameters with brackets (brand[]=canon), search pages, UTM tags from emails, old links with capital letters - Paste 10-30 example URLs (from a crawl, logs or Search Console): /lenses/?brand[]=canon&mount[]=rf /lenses/?brand%5B%5D=canon&mount%5B%5D=rf /lenses/?mount[]=rf&brand[]=canon /Lenses/?brand[]=canon /lenses?brand[]=canon /lenses/?brand[]=canon&utm_source=newsletter&utm_medium=email /search?q=50mm+lens /search?q=50mm%20lens /cameras/full-frame/ /cameras/full-frame /Cameras/Full-Frame/ /lenses/canon-rf-50mm-f1-8/?ref=homepage http://shop.example.com/lenses/canon-rf-50mm-f1-8/ https://example.com/lenses/canon-rf-50mm-f1-8/ - Optional: how the site builds internal links, canonicals, sitemaps and structured data: Internal links come from templates that copy the current URL with its parameters. Canonical tags are built from the requested URL. The sitemap lists category pages with trailing slashes. Product schema uses the URL without a slash.
Real output
Pasted straight from the model. We did not fix a word.
One URL standard for shop.example.com
Your 14 URLs show 9 messy patterns, and your notes add 2 more. You can fix all of them with one function that every part of the site uses: redirects, links, canonicals, sitemap and schema. In the paths below, the host is https://shop.example.com unless a full URL is shown.
The standard
- Host and protocol:
https://shop.example.comonly - Path: lowercase, ends with
/→/cameras/full-frame/,/lenses/canon-rf-50mm-f1-8/,/search/ - Filters: brackets encoded, keys A–Z, values A–Z, lowercase slugs, each value once, no empty params →
/lenses/?brand%5B%5D=canon&mount%5B%5D=rf - Search: spaces as
+, a real plus sign as%2B→/search/?q=50mm+lens - Hex printed in uppercase (
%5B).%5bis the same URL, so it never needs a redirect. - No
utm_*,ref,gclidorfbclidin internal links, canonicals, sitemaps or schema
Why the mess happens (from your notes)
- Templates copy the current URL with its parameters. One messy entry URL (a newsletter click with UTMs, an old capitalized link, a
ref=homepageclick) gets copied into every link on that page. Googlebot then finds a fresh copy of the whole section. This is your biggest source. - Canonicals are built from the requested URL. Every copy says "I am the original", so Google has to pick one itself. That is exactly what "Duplicate, Google chose different canonical than user" reports.
- Sitemap and schema disagree. The sitemap uses trailing slashes and Product schema doesn't, so you give Google two URLs for each product.
- Guess: the encoded URLs come from your filter form (browsers encode
[ ]as%5B%5Dwhen they submit a GET form), and the raw ones come from templates that glue strings together. Both work because PHP reads them the same way, which is why nobody noticed.
1. Pattern table
| Pattern | Example | Clean version | Fix method |
|---|---|---|---|
1. Bracket encoding (raw vs %5B%5D) | /lenses/?brand[]=canon&mount[]=rf | /lenses/?brand%5B%5D=canon&mount%5B%5D=rf | PHP 301 raw → encoded; links via url_for(); canonical from the normalizer |
| 2. Parameter order | /lenses/?mount[]=rf&brand[]=canon | /lenses/?brand%5B%5D=canon&mount%5B%5D=rf | PHP 301 to A–Z key order; filter form fields in A–Z order |
| 3. Capital letters in path | /Lenses/?brand[]=canon, /Cameras/Full-Frame/ | /lenses/?brand%5B%5D=canon, /cameras/full-frame/ | PHP 301 to lowercase path (query values untouched); fix old hardcoded links |
| 4. Missing trailing slash | /lenses?brand[]=canon, /cameras/full-frame | /lenses/?brand%5B%5D=canon, /cameras/full-frame/ | PHP 301 adds the slash |
5. Space encoding (+ vs %20) | /search?q=50mm%20lens, /search?q=50mm+lens | /search/?q=50mm+lens | PHP 301 %20 → + and /search → /search/; search pages noindex, follow |
| 6. Email tracking params | /lenses/?brand[]=canon&utm_source=newsletter&utm_medium=email | Landing: /lenses/?brand%5B%5D=canon&utm_source=newsletter&utm_medium=email. Canonical: /lenses/?brand%5B%5D=canon | Redirect fixes the format but keeps UTMs; canonical drops them; templates never copy them |
| 7. Internal tracking param | /lenses/canon-rf-50mm-f1-8/?ref=homepage | /lenses/canon-rf-50mm-f1-8/ | Remove from homepage template; PHP 301 strips ref; track clicks as analytics events |
| 8. http vs https | http://shop.example.com/lenses/canon-rf-50mm-f1-8/ | https://shop.example.com/lenses/canon-rf-50mm-f1-8/ | Apache 301; HSTS later |
| 9. Wrong host (your www/non-www case) | https://example.com/lenses/canon-rf-50mm-f1-8/ | https://shop.example.com/lenses/canon-rf-50mm-f1-8/ | Apache 301 on whatever answers for example.com |
| 10. Duplicate parameters (not in your sample; hypothetical example) | /lenses/?brand[]=canon&brand[]=canon | /lenses/?brand%5B%5D=canon | Normalizer removes repeats + 301; stops once templates stop copying the current URL |
| 11. Sitemap vs schema slash mismatch (from your notes) | Sitemap: /cameras/full-frame/. Schema: /lenses/canon-rf-50mm-f1-8 | /lenses/canon-rf-50mm-f1-8/ | Print every schema and sitemap URL through the normalizer |
Why each clean version (one line each)
- Encoded brackets: valid under RFC 3986, Google's own advice, and safer for other crawlers and tools. Raw brackets are the old form.
- A–Z keys: a simple rule every template and script can follow, so one set of filters = one URL.
- Lowercase: your sitemap and most links already use it. Capitalized URLs only come from old links.
- Trailing slash: your sitemap and live product links already use it. Only the schema and some links differ, so it is the smallest change.
+for spaces: HTML GET forms send+, so normal searches never hit a redirect.%20only shows up in hand-built links.- UTMs only on the landing URL: your email reports need them when the visitor arrives. Google and your internal links never do.
- No
ref: the same page with a click label is a duplicate. Click tracking belongs in analytics. - https: your stated site address. http doubles every page.
- shop.example.com: your stated site address. Product pages on
example.comsplit links and signals. - Each value once: a repeated filter shows the same page, so it is a duplicate.
- Schema = canonical = sitemap: structured data should name the exact URL that your canonical and sitemap name.
2. How to enforce it
301 redirects
- Apache:
http://and any other host (example.com,www.) →https://shop.example.comin one hop, with path and query untouched. - PHP front controller: everything else in one hop: capitals, missing slash, raw brackets, parameter order, repeated or empty params,
%20andref. - Never strip UTMs or ad click IDs in a redirect. GA4 and Google Ads read
utm_*andgclidon the landing page. The redirect fixes the format and carries them along. The canonical drops them. - Redirect only
GET/HEADrequests for public pages. Leave API/AJAX, cart, checkout, account and payment callback URLs alone. - Most URLs take one hop. The worst case (
http://example.com/Lenses?...) takes two. No longer chains. - Before launch, make sure your router finds every page by its lowercase slug. A 301 to a URL that 404s would break working pages that have backlinks.
- Keep the redirects permanently, or at least a year. They cost nothing.
Canonical tags
- Build the canonical with
normalize_url($_SERVER['REQUEST_URI']), never from the raw requested URL. Use an absolute URL with https and the shop host. - The canonical must be a URL that returns 200 with no redirect. Redirects and canonicals use the same function, so they can't disagree.
- Filter pages point to their own clean URL, not to
/lenses/. "Canon RF lenses" shows different products from "all lenses", and Google tends to ignore canonicals between pages that differ. Deciding which filter combinations should rank is a separate job (faceted navigation). Fix the format first. Guess: if combinations explode once you add more filters, putnoindex, followon pages with 3+ selected values. - UTM and other tracking variants get the clean canonical, with tracking removed.
- Search pages get a clean self canonical plus
<meta name="robots" content="noindex, follow">.
Link rules for templates
- Never build a link from
$_SERVER['REQUEST_URI']or "the current URL". Build it from a route plus the exact parameters the link should set, throughurl_for(). - Product links never carry filter, search, sort or tracking params.
- Filter links: start from the parsed filters (
$_GET), add or remove one value, then callurl_for(). - Filter values are lowercase slugs (
canon,rf), never display names like "Canon". - Filter form: put the fields in A–Z order (brand, then mount), so the browser's own submit already produces the standard. Search form:
action="/search/". - Guess: if your filters update the URL with JavaScript, apply the same rules there.
encodeURIComponent()leaves! ' ( ) *raw while PHP'srawurlencode()encodes them. With slug values this never matters. - Replace
?ref=homepagewith an analytics click event, or adata-attribute that your tag reads.
Parameter handling
- Allow list:
brand[],mount[],q, plus your real extras (guess:page,sort). Only these appear in links and canonicals. - Multi-value params (
[]): lowercase, remove repeats, sort. Single-value params: the last one wins, the same as PHP's$_GET. - Remove empty values (
brand[]=) andpage=1. - Tracking params (
utm_*,gclid,fbclid,msclkid): passed through redirects, never printed by your site. - Guess: if you have
sort=orview=, keep them in links but drop them from canonicals, so sorted views point to the default order. That needs a third list in the code. - Search Console's URL Parameters tool was retired in 2022, so all of this has to happen on your site.
robots.txt: only where it really helps
The trade-off. Blocking a URL in robots.txt stops Google from fetching it. That saves crawl, but Google can no longer see the 301 or the canonical tag on that URL. The blocked URL keeps its links, can still get indexed without a snippet if other pages link to it, and its signals never merge into the clean URL. Leaving it crawlable costs some crawl, but Google sees your redirect or canonical and merges the duplicates.
For your site: don't block filter URLs, raw-bracket, capitalized, no-slash or UTM URLs. During this fix Google must crawl them to see the 301s and canonicals. The real crawl saving comes from fixing internal links: once templates stop printing messy URLs, Googlebot stops finding new ones. robots.txt is a poor tool for brackets anyway, because [ and %5B may be matched as different characters, so a rule for one form can miss the other.
The one place it makes sense is internal search. Step 1: noindex, follow on /search/ pages, and no internal links to search results. Step 2 (optional): once Search Console shows those pages are gone, and only if your logs show Googlebot still spending many hits there, add Disallow: /search/. After step 2 Google can't see the noindex any more, so never do step 2 first.
3. Code
Apache rules
# ---- shop.example.com vhost (or the top of /.htaccess) ----
RewriteEngine On
# 1) http:// and any other host (example.com, www.example.com, www.shop.example.com)
# -> https://shop.example.com in ONE hop.
# The target has no "?", so Apache passes the original query string through
# unchanged. PHP fixes the query on arrival.
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^shop\.example\.com$ [NC]
RewriteRule ^ https://shop.example.com%{REQUEST_URI} [R=301,L]
# GUESS: if TLS ends at a load balancer or CDN, %{HTTPS} is always "off" here
# and the rule above loops. In that case test the proxy header instead:
# RewriteCond %{HTTP:X-Forwarded-Proto} !=https [OR]
# 2) Keep your existing front-controller rule. Capitals, trailing slash and the
# whole query string are fixed in PHP: mod_rewrite can't sort or re-encode
# query params, and lowercasing needs a RewriteMap that only works in the
# vhost config. Doing it all in PHP means one 301 per messy URL, not a chain.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]
# 3) After https has worked for a week, add HSTS (needs mod_headers, https vhost only).
# Start short, then raise to 31536000 (one year).
# Header always set Strict-Transport-Security "max-age=86400"
# ---- ONLY if example.com is a separate site with its own vhost or server ----
# GUESS: since example.com serves your product URL, it probably points at the
# same app and rule 1 above already covers it. If it is a different site, send
# only the store paths and leave the main site alone. List ALL store sections.
RewriteEngine On
RewriteRule ^/?(lenses|cameras|search)(/|$) https://shop.example.com%{REQUEST_URI} [NC,R=301,L]
# robots.txt: nothing for filters or messy variants. Google must crawl them
# to see the 301s and canonicals.
User-agent: *
# Optional, step 2 only, after /search/ pages have left the index via noindex:
# Disallow: /search/
# Disallow: /search?
# GUESS: adjust if your sitemap file has another name
Sitemap: https://shop.example.com/sitemap.xml
PHP URL normalizer
<?php
// url.php: one URL format for https://shop.example.com (PHP 7.1+)
//
// One standard for redirects, links, canonicals, sitemap and schema:
// https://shop.example.com only (Apache handles http:// and other hosts)
// lowercase path, no "//", every page path ends in "/" (files don't)
// brackets encoded as %5B%5D, spaces as "+", a real plus as %2B, uppercase hex
// content params sorted A-Z, multi-values sorted and de-duplicated, empty ones removed
// tracking params (utm_*, gclid, fbclid ...) never printed, only carried through a 301
const CANON_ORIGIN = 'https://shop.example.com';
// Params that change what the page shows. Kept in links and canonicals.
// GUESS: your site has more than the sample shows (page, sort, price...).
// List them all here, or links built with url_for() will drop them.
const CONTENT_PARAMS = ['brand[]', 'mount[]', 'q', 'page'];
// Removed everywhere, even from redirects (internal click labels).
const DROP_PARAMS = ['ref'];
// Paths that end like this are files: no trailing slash.
const FILE_EXT = '/\.(jpe?g|png|webp|gif|svg|ico|css|js|xml|txt|pdf|php)$/';
function encode_part(string $s): string
{
// rawurlencode = RFC 3986: uppercase hex, [ ] -> %5B %5D, + -> %2B, space -> %20.
// Then "+" for spaces, which is what your GET search form already sends.
return str_replace('%20', '+', rawurlencode($s));
}
function upper_hex(string $url): string
{
// %5b and %5B are the same URL. Compare in one case so we never redirect for that alone.
return preg_replace_callback('/%[0-9a-f]{2}/i', function ($m) { return strtoupper($m[0]); }, $url);
}
/**
* normalize_url('/Lenses?mount[]=rf&brand[]=canon&utm_source=x')
* -> https://shop.example.com/lenses/?brand%5B%5D=canon&mount%5B%5D=rf
* normalize_url('/Lenses?mount[]=rf&brand[]=canon&utm_source=x', true) // 301 target
* -> https://shop.example.com/lenses/?brand%5B%5D=canon&mount%5B%5D=rf&utm_source=x
*/
function normalize_url(string $url, bool $forRedirect = false): string
{
$url = preg_replace('/#.*/', '', $url); // fragments never reach the server
$url = preg_replace('#^[a-z][a-z0-9+.-]*://[^/?]*#i', '', $url); // drop scheme + host if given
[$path, $query] = array_pad(explode('?', $url, 2), 2, '');
// 1) Path: lowercase, drop empty segments ("//"), trailing slash on pages.
$segments = [];
foreach (explode('/', $path) as $seg) {
if ($seg !== '') {
$segments[] = rawurlencode(strtolower(rawurldecode($seg)));
}
}
$path = '/' . implode('/', $segments);
if ($path !== '/' && !preg_match(FILE_EXT, $path)) {
$path .= '/';
}
// 2) Query: parsed by hand. parse_str() + http_build_query() would print
// brand[]=canon as brand%5B0%5D=canon, which is yet another URL format.
$params = [];
foreach (explode('&', $query) as $pair) {
if ($pair === '') continue;
[$key, $value] = array_pad(explode('=', $pair, 2), 2, '');
$key = urldecode($key); // brand%5B%5D and brand[] -> brand[]
$value = trim(urldecode($value)); // "+" and "%20" -> space
if (substr($key, -2) === '[]') {
$value = strtolower($value); // filter values are slugs: Canon -> canon
}
if ($value === '' || in_array($key, DROP_PARAMS, true)) continue;
if ($key === 'page' && $value === '1') continue; // page 1 = no page param
$params[$key][] = $value;
}
$content = [];
$extra = [];
foreach ($params as $key => $values) {
$values = array_values(array_unique($values)); // brand[]=canon twice -> once
if (substr($key, -2) === '[]') {
sort($values, SORT_STRING); // sony, canon -> canon, sony
} else {
$values = [end($values)]; // q=a&q=b -> last wins, like $_GET
}
if (in_array($key, CONTENT_PARAMS, true)) {
$content[$key] = $values;
} elseif ($forRedirect) {
$extra[$key] = $values; // utm_*, gclid, unknown: keep, original order
}
}
ksort($content, SORT_STRING); // brand[] before mount[]
$pairs = [];
foreach ($content + $extra as $key => $values) {
foreach ($values as $v) {
$pairs[] = encode_part($key) . '=' . encode_part($v);
}
}
return CANON_ORIGIN . $path . ($pairs ? '?' . implode('&', $pairs) : '');
}
// Build internal links from a route + explicit params, never from the current URL.
// url_for('/lenses/', ['brand[]' => ['canon'], 'mount[]' => ['rf']])
function url_for(string $path, array $params = []): string
{
$pairs = [];
foreach ($params as $key => $values) {
foreach ((array) $values as $v) {
$pairs[] = rawurlencode($key) . '=' . rawurlencode((string) $v);
}
}
return normalize_url($path . ($pairs ? '?' . implode('&', $pairs) : ''));
}
Using it (front controller and templates)
<?php
// index.php: at the very top of the front controller, before any output
require __DIR__ . '/url.php';
// GUESS: adjust to your routes. Only public pages are redirected. Never touch
// API/AJAX, admin, cart, checkout, account or payment-callback URLs.
$isPublicPage = !preg_match('#^/(api|ajax|admin|cart|checkout|account|payment)(/|\?|$)#i',
$_SERVER['REQUEST_URI']);
if ($isPublicPage && in_array($_SERVER['REQUEST_METHOD'], ['GET', 'HEAD'], true)) {
// Raw URL as the client sent it. Apache has already fixed scheme + host.
$requested = CANON_ORIGIN . $_SERVER['REQUEST_URI'];
$target = normalize_url($_SERVER['REQUEST_URI'], true);
if (upper_hex($requested) !== $target) {
// If any report still reads ?ref=, log it here before it is dropped.
header('Location: ' . $target, true, 301);
exit;
}
}
// The same function makes the canonical (tracking removed), so the two always agree.
$canonical = normalize_url($_SERVER['REQUEST_URI']);
<!-- <head> -->
<link rel="canonical" href="<?= htmlspecialchars($canonical) ?>">
<?php if ($route === 'search'): /* GUESS: your route variable */ ?>
<meta name="robots" content="noindex, follow">
<?php endif; ?>
<!-- Product card: clean product URL, no filters, no tracking -->
<a href="<?= htmlspecialchars(url_for('/lenses/' . $product['slug'] . '/')) ?>">...</a>
<!-- Filter link "add Sony": start from the parsed filters, not the URL string.
htmlspecialchars() turns & into &, which is correct HTML; browsers and Google read it as &. -->
<?php $href = url_for('/lenses/', [
'brand[]' => array_merge((array) ($_GET['brand'] ?? []), ['sony']),
'mount[]' => (array) ($_GET['mount'] ?? []),
]); ?>
<a href="<?= htmlspecialchars($href) ?>">Sony</a>
<!-- Product schema: same URL as the canonical, WITH the trailing slash -->
"url": <?= json_encode(url_for('/lenses/' . $product['slug'] . '/'), JSON_UNESCAPED_SLASHES) ?>,
4. Update checklist
Rollout order: ship links, canonicals and PHP redirects in one release, so no internal link ever points at a redirect. Do the sitemap and schema the same day, then ads and email, and only later (if needed) robots.txt for /search/.
Templates
- Replace every link built from the current URL with
url_for(): main menu, breadcrumbs, category grids, product cards, filter links and checkboxes, "clear filters", pagination, related products, footer, 404 page. - Product cards and related-product links carry no filter, search, sort or tracking params.
- Filter form: fields in A–Z order (brand, then mount); values are lowercase slugs.
- Search form:
method="get",action="/search/", field nameq. Also update any autocomplete script that calls/search. - Remove
?ref=homepage(and any otherref=) from homepage blocks; add analytics click events instead. - Guess: JavaScript that builds or pushes URLs (AJAX filters,
history.pushState) follows the same rules. - Router finds pages by lowercase slug (test before switching on the redirect).
Hardcoded links (old links with capitals)
- Search product descriptions, CMS blocks and blog posts in the database for
href="/followed by capitals,http://shop.,//example.com/, raw[],ref=, and fix them at the source. Example:SELECT id FROM products WHERE description REGEXP BINARY 'href="/[^"]*[A-Z]';(guess at table and column names). - Existing redirect maps for old URLs point straight at the final standard URL (no chains).
Canonical tags
- Every page:
normalize_url($_SERVER['REQUEST_URI']), absolute. - Search pages: also
noindex, follow. -
og:url= canonical.
XML sitemap
- Generate every URL through
normalize_url(). Categories already have the slash; also confirm lowercase, https and the shop host. - Add product pages if they're not in any sitemap. Your notes only mention category pages (guess: you may have a separate product sitemap; check).
- Only 200, self-canonical URLs. No search, UTM or
refURLs. Filter URLs only if you decide to index them, with&written as&in the XML. - Resubmit the sitemap in Search Console.
Structured data
- Product
urlandoffers.url→ with trailing slash. -
@idvalues, BreadcrumbListitemURLs, Organization/WebSiteurl. - Check a category and a product page in the Rich Results Test.
hreflang
- Not in your notes (guess: single-language store). If you have it or add it: every hreflang URL uses the standard, returns 200, matches the canonical and is reciprocal.
Ads
- Google Ads final URLs (ads, sitelinks, other assets) → standard URLs. Keep auto-tagging;
gclidsurvives the redirect, but don't rely on the redirect. - Meta and other ad platforms: standard base URL, with UTMs in the URL parameters field.
- Guess (if you run Shopping ads): Merchant Center feed
linkuses the standard URL with the slash, matching the canonical.
- Newsletter templates and automated emails (order confirmation, abandoned cart): standard base URL, content params first, UTMs last.
- Send a test email and click each link type through your email platform's click tracking. The final URL should be the standard + UTMs, with no extra hop on your site.
Server and other
- Apache host/scheme rule on every vhost that answers for
http://,example.comandwww.. - Purge any page cache or CDN after release, so old HTML with old links and canonicals isn't served.
- HSTS: start short, raise to one year after a week with no issues.
- Profiles you control (Google Business Profile, social bios, marketplace listings) →
https://shop.example.com/. - Top backlinks with capitals, http or
example.comare covered by 301s. Optionally ask the most valuable sites to update them.
5. Before and after test plan
Before: baseline (save everything)
- Full crawl from the homepage (Screaming Frog or Sitebulb). Turn on JavaScript rendering if your filters use JS (guess). Record:
- HTML URLs found vs. unique pages (exact-duplicate clusters)
- URLs with raw
[, with%5B, with capitals in the path, without a trailing slash, withutm_, withref= - pages whose canonical isn't the standard version of their own URL
- internal links pointing at any of those variants
- List crawl: your 14 sample URLs + the top linked pages from Search Console's Links report (and any backlink tool). Record the status codes. After launch, every one of these must end on a 200.
- Logs: 30 days of Googlebot hits per pattern (commands below).
- Search Console (use a Domain property, so http, https,
example.comandshop.all show up): note the Page indexing counts in the table further down and export the example URLs. Run URL Inspection on the 14 samples and note the user-declared vs. Google-selected canonical. Note the share of 301s in Crawl stats. - GA4: baseline sessions for source/medium
newsletter / email.
Release day (staging first, then live)
Every request should give this first response, and the final page must return 200:
| Request | First response | Canonical on the final page |
|---|---|---|
/lenses/?brand[]=canon&mount[]=rf | 301 → /lenses/?brand%5B%5D=canon&mount%5B%5D=rf | itself |
/lenses/?brand%5B%5D=canon&mount%5B%5D=rf | 200 | itself |
/lenses/?mount[]=rf&brand[]=canon | 301 → /lenses/?brand%5B%5D=canon&mount%5B%5D=rf | itself |
/Lenses/?brand[]=canon | 301 → /lenses/?brand%5B%5D=canon | itself |
/lenses?brand[]=canon | 301 → /lenses/?brand%5B%5D=canon | itself |
/lenses/?brand[]=canon&utm_source=newsletter&utm_medium=email | 301 → /lenses/?brand%5B%5D=canon&utm_source=newsletter&utm_medium=email | /lenses/?brand%5B%5D=canon |
/search?q=50mm+lens | 301 → /search/?q=50mm+lens | itself + noindex |
/search?q=50mm%20lens | 301 → /search/?q=50mm+lens | itself + noindex |
/cameras/full-frame/ | 200 | itself |
/cameras/full-frame | 301 → /cameras/full-frame/ | itself |
/Cameras/Full-Frame/ | 301 → /cameras/full-frame/ | itself |
/lenses/canon-rf-50mm-f1-8/?ref=homepage | 301 → /lenses/canon-rf-50mm-f1-8/ | itself |
http://shop.example.com/lenses/canon-rf-50mm-f1-8/ | 301 → https://shop.example.com/lenses/canon-rf-50mm-f1-8/ | itself |
https://example.com/lenses/canon-rf-50mm-f1-8/ | 301 → https://shop.example.com/lenses/canon-rf-50mm-f1-8/ | itself |
# sample-urls.txt = the 14 URLs above as full URLs (https://shop.example.com/...)
# -g stops curl from treating [ ] as its own glob ranges.
while read -r u; do
first=$(curl -sg -o /dev/null -w '%{http_code} %{redirect_url}' "$u")
final=$(curl -sgL -o /dev/null -w '%{http_code} hops=%{num_redirects} %{url_effective}' "$u")
echo "$u | $first | $final"
done < sample-urls.txt
# Canonical on a final page (should have no utm_ in it)
curl -sgL "https://shop.example.com/lenses/?brand[]=canon&utm_source=newsletter&utm_medium=email" \
| grep -o '<link rel="canonical"[^>]*>'
# Googlebot hits per pattern (point at your Apache access logs; run before and after).
# Anyone can fake the user agent, but it's fine for trend counts.
zgrep -h Googlebot access.log* | grep -cE '"GET [^ "]*\[' # raw brackets
zgrep -h Googlebot access.log* | grep -ciE '"GET [^ "]*%5B' # encoded brackets
zgrep -h Googlebot access.log* | grep -cE '"GET /[^ ?"]*[A-Z]' # capitals in path
zgrep -h Googlebot access.log* | grep -cE '"GET [^ "]*[?&](utm_|ref=)' # tracking params
Also check on release day:
- Every clean URL returns 200 with no redirect. This proves the normalizer gives the same result when run twice, so redirects can't loop.
- Your backlink list from step 2: all URLs end on a 200 standard URL. No 404s.
- Cart, checkout, payment callbacks, account and any API/AJAX calls still work (they are excluded from the redirect).
- Search and filter forms submit straight to the standard URL with no redirect.
- Test email: GA4 shows the session as
newsletter / emailafter the redirect. Google Ads test click:gclidis still on the landing URL.
After: re-crawl with the same settings and compare
| Metric (crawl) | Before | Target after |
|---|---|---|
| HTML URLs found vs. unique pages | record | gap near 0 |
URLs with raw [ | record | 0 |
| Internal links pointing at a 301 | record | 0 |
Internal links with utm_ or ref= | record | 0 |
| 200 pages with capitals or no trailing slash | record | 0 |
| Pages whose canonical isn't their standard URL | record | 0 |
| Exact-duplicate clusters | record | only real duplicates left (if any) |
| Sitemap URLs that aren't 200 + self-canonical | record | 0 |
Weeks 1–8 in Search Console
| Page indexing reason | What to expect |
|---|---|
| Duplicate, Google chose different canonical than user | Falls steadily. This is your main success metric. |
| Duplicate without user-selected canonical | Falls (every page now has a correct canonical) |
| Page with redirect | Rises first as the variants fold into the standard, then levels off. This is expected. |
| Alternate page with proper canonical tag | May rise (UTM variants). This is fine. |
| Excluded by 'noindex' tag | Rises by your search pages. This is expected. |
- Run URL Inspection on the 14 samples each week: the Google-selected canonical should match the user-declared one. Click "Validate fix" once the duplicate count drops.
- Crawl stats and logs: the 301 share rises, then falls as Googlebot stops finding new messy URLs. Hits on raw-bracket and capitalized variants should trend toward 0.
- Guess on timing: 2–8 weeks for most changes to show, depending on how often Google crawls these pages.
- Red flags (roll back the PHP redirect, keep the link fixes): rising 404s, any redirect loop,
newsletter / emailsessions dropping well below baseline, or a drop in Google Ads conversions.
The prompt
First lines open so you can see how it is built. The rest opens after purchase.
#ROLE You are a technical SEO expert in URL structure, canonicalization and URL encoding. Help me find inconsistent URL formats on my site and fix them with one clean standard. #INPUTS Fill in every line. Leave a line blank if you don't know it. - Website: [WEBSITE URL] - Platform: [e.g., Shopify, Magento, WooCommerce, custom] - Where messy URLs come from: [e.g., filter parameters like color[]=red, search pages, tracking tags, old links]
How to use it
- Buy, then open it in your account.
- Copy the prompt into ChatGPT, Claude or Gemini.
- Replace the 5 inputs with your product.
- Run it. Use the output. Re-run with a different tone if you like.
Pro tips
- Paste URLs from a crawl, not from memory. The real variations are always stranger than you expect.
- Fix templates first. Redirects clean up old URLs, but templates stop new messy ones from being created.
- Compare duplicate counts in a crawl before and after. That's your proof the fix worked.
Before you buy
- Will it work for my product?
- Yes, if you can fill the 5 inputs. If the output is bad with your inputs, email us: we fix the prompt and refund you.
- Do I download a file?
- No. It lives in your account with a copy button, and updates when we improve it.
- Which model is best?
- Best on Claude. Works in ChatGPT, Claude and Gemini.
Works well with this
Prompts people use in the same campaign.
More in Site Structure, URLs & Media
Buying more than two? Lifetime is cheaper.
Every prompt, every category, forever. $59 once. Nothing to download, nothing to renew.
This prompt
$3$7
- ✓ Instant access in your account, with a copy button
- ✓ Example input and real output included
- ✓ 7-day money-back, no form
Or get every prompt, forever
Lifetime Access · $59 $149 — all categories, all future prompts, rewrites included.
Get lifetime accessCard or PayPal · taxes at checkout · nothing to download
Not the one you need?
Browse every prompt by category and sub-category.