Clear Trailing Slash
Overview
The ClearLastSlash rule in Forge Server's forgerc configuration removes a trailing slash from URLs when enabled. This rule can be applied globally to all URLs or nested within a Location block for more granular control.
Usage
The ClearLastSlash rule accepts a boolean value:
trueâ Enables the removal of the trailing slashfalseâ Disables the removal of the trailing slash (default behavior if not specified)
Global Configuration
Applying ClearLastSlash globally ensures that all URLs processed by the server automatically remove a trailing slash if present.
Example
ClearLastSlash true
Location /sdk
Rewrite /sdk/index.html
Location /guides/deployment-options
Rewrite /guides/deployment-options/index.html
In this example:
ClearLastSlash trueensures that all URLs have their trailing slash removed before further processing- The Rewrite directives inside Location blocks remain unaffected by this rule
How It Works
When ClearLastSlash is enabled:
- URL Processing: All incoming URLs are processed to remove trailing slashes
- Location Matching: Location blocks match against the cleaned URLs
- Rewrite Rules: Rewrite directives work with the normalized URLs
- Consistent Behavior: All URLs follow the same pattern
Benefits
Using ClearLastSlash provides several advantages:
- URL Consistency: All URLs follow the same format
- SEO Improvement: Prevents duplicate content issues
- Clean URLs: More professional and readable URLs
- Simplified Routing: Easier to manage URL patterns
- Search Engine Friendly: Better indexing and crawling
Considerations
- Ensure that enabling
ClearLastSlashdoes not conflict with expected routing behavior in your application - URLs without a trailing slash remain unchanged
Best Practices
Follow these best practices when using ClearLastSlash:
- Test thoroughly in development before deploying
- Monitor for any routing conflicts or issues
- Update internal links to match your URL strategy
- Consider the impact on existing bookmarks and links
- Document your URL strategy for team members
Join the Discussion
Have questions or want to share your experience? Join our community discussion to connect with other developers and get help from the Forge team.
Visit Forum Discussion