URL Rules
Rules for validating URL structure and SEO.
url-length
Checks URL path length.
Thresholds
Good: <75 characters
Warning: 75-100 characters
Poor: >100 characters
Checks
URL path length
Nesting depth (>4 levels)
Examples
Info:
/blog/2024/january/15/my-really-long-and-detailed-blog-post-title-about-something
<!-- Info: URL path is long (70 chars). Aim for <75. -->
Warning:
/products/electronics/computers/laptops/gaming/high-performance/model-xyz-2024
<!-- Warning: URL nested too deeply (7 levels). Aim for ≤4. -->
Pass:
/blog/react-hooks-guide
/products/laptop-xyz
Configuration
rules: {
'url-length': {
severity: 'info',
},
}
url-structure
Validates URL formatting conventions.
Checks
Uses hyphens not underscores
Lowercase letters
No excessive query parameters (>3)
No special characters
No spaces or double slashes
Examples
Warning (underscores):
/blog/my_blog_post
<!-- Warning: Use hyphens instead of underscores -->
Warning (uppercase):
/Blog/My-Post
<!-- Warning: URLs should be lowercase -->
Warning (special chars):
/blog/my-post!-amazing
<!-- Warning: URL contains special characters -->
Info (many params):
/search?q=term&sort=date&filter=new&page=1&limit=10
<!-- Info: URL has many query parameters (5) -->
Pass:
/blog/my-blog-post
/products/widget-pro
/guides/getting-started
Configuration
rules: {
'url-structure': {
severity: 'warning',
},
}
url-keywords
Checks URL contains relevant keywords.
Checks
URL contains words from title
Avoids generic patterns (page-1, post-123)
No UUIDs in URL
Examples
Info:
<title>React Hooks Complete Guide</title>
URL: /posts/12345
<!-- Info: URL doesn't contain title keywords -->
<!-- Consider: /posts/react-hooks-guide -->
Info:
URL: /product/a1b2c3d4-e5f6-7890-abcd-ef1234567890
<!-- Info: URL contains UUID. Consider human-readable slug. -->
Pass:
<title>React Hooks Guide</title>
URL: /guides/react-hooks
Configuration
rules: {
'url-keywords': {
severity: 'info',
},
}
url-trailing-slash
Ensures consistent trailing slash usage.
Checks
URL matches canonical trailing slash
Consistency across site
Examples
Info:
URL: /about/
<link rel="canonical" href="https://example.com/about">
<!-- Info: Trailing slash mismatch between URL and canonical -->
Pass:
URL: /about
<link rel="canonical" href="https://example.com/about">
URL: /about/
<link rel="canonical" href="https://example.com/about/">
Configuration
rules: {
'url-trailing-slash': {
severity: 'info',
},
}
URL Best Practices
Do
Use hyphens: /my-page
Keep short: /blog/react-guide
Include keywords: /guides/react-hooks
Use lowercase: /about-us
Be descriptive: /products/widget-pro
Don't
Use underscores: /my_page
Use IDs only: /posts/12345
Use UUIDs: /p/a1b2c3d4-...
Use uppercase: /About-Us
Use special chars: /my-post!
URL Structure Examples
Good
/ # Home
/about # About page
/blog # Blog index
/blog/react-hooks-guide # Blog post
/products # Products index
/products/widget-pro # Product page
/docs/getting-started # Documentation
Bad
/page.php?id=123 # Query string ID
/blog/2024/01/15/post # Date in URL (unless needed)
/p/a1b2c3d4 # UUID
/Blog/My_Post # Mixed case, underscores
/products?cat=1&sub=2&p=3 # Many parameters
Redirect Handling
When changing URLs:
301 Redirect old URL to new
Update internal links to use new URL
Update sitemap
Update canonical tags
# nginx
location /old-page {
return 301 /new-page;
}