Help Center
Find answers or browse our knowledge base.
Latest Questions
Add htaccess
Ship your add-on with custom rewrite rules and they will be auto-added to the site’s root .htaccess if /modules/{addonid}/.htaccess exists.
This function lets your addon provide its own rewrite rules (for pretty URLs, custom endpoints, etc.). When the addon is activated, the contents of its .htaccess file are automatically merged into the main site .htaccess.
How it works
- Checks if /modules/{addonid}/.htaccess is present.
- If found, reads its content and wraps it between markers:
# BEGIN {addonid} Addon Rules
...rules here...
# END {addonid} Addon Rules
- Appends the block to the main /.htaccess file (skipping if already injected).
- On deactivation, uninject_htaccess_rules($plugin_name) removes the block between these markers.
Where to place rules
- Create /modules/{addonid}/.htaccess in your addon folder.
- Add the rewrite rules or redirects needed for your addon pages.
Example:
# Pretty URL for addon pages
RewriteRule ^books/?$ index.php?view=books [L,QSA]
# Book detail by slug
RewriteRule ^books/view/([^/]+)/?$ index.php?view=books&slug=$1 [L,QSA]
How to use in your addon
- When creating new routes (e.g., /books, /jobs, /forums), define the rules in your module’s .htaccess.
- Use clean, specific patterns so they don’t override core URLs.
- Rely on your module’s index.php to handle the request after rewrite.
Best Practices
- Always wrap your addon rules with clear patterns (avoid conflicts with core routes).
- Keep addon rules separate in /modules/{addonid}/.htaccess so they are easy to manage.
- On activation, inject_htaccess_rules($plugin_name) merges them into root .htaccess with markers.
- On deactivation, uninject_htaccess_rules($plugin_name) removes them cleanly.
Was this answer helpful?
You must login to vote.
0 found this helpful,
0 did not
How could it be better?
What went wrong?
Thank you for your feedback!