Problem
Google Search Console reported duplicate content issues for URLs with query parameters like:
https://rkoots.github.io/styleguide/jsguide?src=187https://rkoots.github.io/styleguide/jsguide?src=71https://rkoots.github.io/styleguide/jsguide?src=177
These URLs were being treated as separate pages without canonical URLs, causing indexing problems.
Solution Implemented
1. Enhanced Canonical Enforcer (assets/js/canonical-enforcer.js)
- Before: Used
history.replaceState()which only changed browser URL - After: Added proper redirect logic for
src=parameters using:- Meta refresh tags for search engines
noindexmeta tags- Actual HTTP redirects after processing
- Maintained
replaceState()for non-critical parameters
2. Server-Side Redirects (_redirects)
Added redirect rules to strip query parameters:
# Remove query parameters for SEO (canonical URLs)
/guide/styleguide/jsguide /guide/styleguide/jsguide/ 301
/guide/styleguide/* /guide/styleguide/:splat 301
3. HTTP Headers (_headers)
Already had proper X-Robots-Tag: noindex, nofollow for parameter URLs:
/*?*
X-Robots-Tag: noindex, nofollow
4. Enhanced SEO Meta Tags (_includes/seo-meta-tags.html)
- Improved canonical URL generation with clean URL variable
- Added immediate JavaScript redirect for
src=parameters - Enhanced OpenGraph tags to use clean URLs
- Added conditional noindex meta tags
5. Robots.txt Protection
Already had proper blocking rule:
Disallow: /*?*
How the Solution Works
Layer 1: Prevention (robots.txt)
- Search engines are instructed not to crawl any URLs with query parameters
Layer 2: Server Headers (_headers)
- Any parameter URLs that slip through get
noindex, nofollowheaders - Prevents indexing at the HTTP level
Layer 3: Server Redirects (_redirects)
- 301 redirects strip parameters and point to clean URLs
- Consolidates link equity to canonical URLs
Layer 4: Page-Level Protection (SEO meta tags)
- Conditional noindex tags for parameter URLs
- Clean canonical URLs in meta tags
- Immediate JavaScript redirect for critical parameters
Layer 5: Client-Side Enforcement (canonical-enforcer.js)
- JavaScript-based redirect and canonical tag management
- Handles edge cases and reinforces other layers
Expected Results
- Immediate: Parameter URLs will redirect to clean URLs
- Short-term: Google will see proper canonical tags and noindex directives
- Medium-term: Duplicate content reports will decrease
- Long-term: Only clean URLs will be indexed and ranked
Monitoring
Check Google Search Console for:
- Reduction in duplicate content errors
- Proper indexing of clean URLs
- No new parameter URLs being indexed
Files Modified
assets/js/canonical-enforcer.js- Enhanced redirect logic_redirects- Added parameter stripping rules_includes/seo-meta-tags.html- Enhanced meta tags and redirects
Testing
To test the solution:
- Visit
https://rkoots.github.io/guide/styleguide/jsguide?src=test - Should redirect to
https://rkoots.github.io/guide/styleguide/jsguide/ - Check browser network tab for redirect chain
- Verify canonical meta tag points to clean URL