A powerful Moodle admin tool plugin for managing custom redirects and 404 error handling.
If you find Redirect Plus useful, please consider supporting its continued development!
While not required, donations help keep this plugin free, up-to-date, and feature-rich. Every little bit helps! 🙏
Quick and easy - any amount appreciated!
Your support makes a difference! It helps me dedicate more time to:
- Adding new features
- Fixing bugs promptly
- Maintaining compatibility with new Moodle versions
- Providing support to users
- Creating documentation and tutorials
Thank you for using Redirect Plus! 🎉
Redirect Plus is a comprehensive solution that gives you complete control over your Moodle site's redirects and 404 error handling. Create custom redirects with optional conditional logic based on user login status or language preference. The plugin also records 404 errors and allows you to customize how they are handled - either display a custom message or redirect users to a specific page.
Custom Redirects:
- Create redirects for any URL (existing pages or 404 errors)
- Add conditional logic based on user login status (logged in vs. logged out)
- Configure language-based redirects for multilingual sites
- Redirect existing pages like homepage, /faq/, or any other page
- Enable/disable individual redirects without deleting them
404 Error Management: The plugin captures comprehensive information about each 404 error including:
- The URL that generated the 404 error
- The referrer (where the user came from)
- User information (who encountered the error)
- IP address
- User agent (browser/device information)
- Timestamp
This information is invaluable for:
- Identifying and fixing broken links
- Improving site navigation
- Understanding user behavior
- Maintaining a better user experience
- Automatic 404 Error Logging: No configuration needed - works automatically after installation
- Custom URL Redirects: Create conditional redirects for ANY page (existing or 404)
- Conditional Parameters: Redirect based on login status and user language
- Redirect Existing Pages: Redirect homepage, /faq/, or any existing page based on conditions
- Administrator Bypass: Disable redirects for administrators (useful for testing)
- Comprehensive Error Report: View all 404 errors in an easy-to-read table format
- User-Friendly Interface: Access the report from Site administration > Tools > Redirect Plus
- Record Management: Delete individual records or clear all records at once
- Pagination Support: Easily browse through large numbers of errors
- Full User Context: See which users encountered errors and when
- Compatible with Moodle 4.3, 4.4, 4.5, 5.0, and 5.1
- Moodle 4.3 or later (compatible with 4.3, 4.4, 4.5, 5.0, and 5.1)
- PHP 7.4 or later
- Download or create a ZIP file of the plugin
- Log in to your Moodle site as an admin and go to Site administration > Plugins > Install plugins
- Upload the ZIP file with the plugin code
- Check the plugin validation report and finish the installation
- The database table
tool_redirectplus_404will be created automatically
- Extract the plugin files
- Copy the
redirectplusfolder to{your/moodle/dirroot}/admin/tool/redirectplus - Log in to your Moodle site as an admin and go to Site administration > Notifications
- Follow the on-screen instructions to complete the installation
- Copy the plugin files to
{your/moodle/dirroot}/admin/tool/redirectplus - Run the upgrade script:
php admin/cli/upgrade.php
Important: After installation, you must configure your web server to enable 404 error logging.
HIGHLY RECOMMENDED: Access to your Apache or Nginx server configuration files is strongly preferred for optimal performance and reliability. The .htaccess method should only be used as a last resort fallback.
Why server configuration is preferred:
- Reliability: Works consistently across all PHP configurations (PHP-FPM, FastCGI, mod_php)
- Performance: More efficient than
.htaccessfile-based configuration - Compatibility: The
.htaccessauto-prepend method does NOT work with PHP-FPM or FastCGI (most modern hosting) - Stability: Avoids potential 500 Internal Server Errors
- Best Practice: Follows Moodle and industry security standards
- Install the plugin (see Installation section above)
- Navigate to the plugin: Site administration > Redirect Plus
- Go to the "Setup Instructions" tab
- Copy your custom 404 URL (shown on the page)
- Configure your web server using Apache or Nginx server configuration (RECOMMENDED)
- Test the setup using the automated test button
- Configure behavior in the Settings tab (optional)
Add this line to your Apache server configuration or virtual host file:
ErrorDocument 404 /admin/tool/redirectplus/error404.php?url=%{REQUEST_URI}Important: The ?url=%{REQUEST_URI} parameter passes the original URL to the error handler.
Why this method is recommended:
- Works with all PHP configurations (mod_php, PHP-FPM, FastCGI)
- Best performance and reliability
- Industry standard approach
Add this line to your Nginx server configuration block:
error_page 404 /admin/tool/redirectplus/error404.php?url=$request_uri;Important: The ?url=$request_uri parameter passes the original URL to the error handler.
Why this method is recommended:
- Works with all PHP configurations
- Best performance and reliability
- Industry standard approach
Known Issues:
- Does NOT work with PHP-FPM or FastCGI (most modern hosting uses these)
- May cause 500 Internal Server Error
- Requires mod_php and specific Apache settings
- Has performance implications
- Not supported on many hosting providers
Only use this method if:
- You cannot access your Apache server configuration
- You have confirmed you are using mod_php (not PHP-FPM or FastCGI)
- You have made a backup of your
.htaccessfile
Add this line to your .htaccess file in Moodle root directory:
ErrorDocument 404 /admin/tool/redirectplus/error404.php?url=%{REQUEST_URI}If you get a 500 error after adding this line:
- Immediately remove the line
- Restore your
.htaccessbackup - Contact your hosting provider to request access to Apache or Nginx server configuration
- Use the Apache or Nginx server configuration method instead
- Log in to your Plesk control panel
- Go to Websites & Domains > your domain > Apache & nginx Settings
- Scroll down to "Additional directives for HTTP"
- Add:
ErrorDocument 404 /admin/tool/redirectplus/error404.php?url=%{REQUEST_URI} - Click "Apply" and "OK"
- Log in as an administrator
- Navigate to Site administration > Redirect Plus (under General section)
- You'll see three tabs: Error Report, Settings, and Setup Instructions
View all recorded 404 errors with:
- URL that generated the error
- Referrer (where the user came from)
- User who encountered the error
- IP address
- User agent (browser/device)
- Date and time
Managing Records:
- Delete a single record: Click the "Delete" button next to any record
- Delete all records: Click the "Delete All Records" button
- Pagination: 50 records per page by default
Configure how 404 errors are handled:
Choose Behavior:
- Use the dropdown to select either:
- Show custom message (default): Display a custom HTML message on the error page
- Redirect to another page: Automatically redirect users to a different URL
Depending on your choice:
- Custom Message: A rich text editor appears where you can create your 404 message with HTML formatting
- Redirect URL: A simple URL field appears where you enter the destination page
Save your settings when done.
Create intelligent redirects with conditional parameters:
Example Use Cases:
-
Homepage Language Redirect:
- Source URL:
/ - Condition: User language
- Spanish speakers →
/es/ - French speakers →
/fr/ - Others →
/en/
- Source URL:
-
FAQ for Guests:
- Source URL:
/faq/ - Condition: Login status
- Logged out →
/guest-faq.html - Logged in → stay on /faq/
- Source URL:
-
Members Area:
- Source URL:
/members/ - Condition: Login status
- Logged in →
/dashboard/ - Logged out →
/login/
- Source URL:
-
Old Page Redirect:
- Source URL:
/old-page - Simple redirect →
/new-page
- Source URL:
Redirect Types:
- Simple Redirect: One URL for everyone
- Conditional Redirect: Different URLs based on:
- Login status (logged in vs. logged out)
- User language (browser or Moodle preference)
- Both conditions combined
Important Notes:
- Works automatically for both existing pages and 404 errors using Moodle's callback system
- No special PHP configuration required (works with PHP-FPM, FastCGI, mod_php, etc.)
- Admin bypass option prevents redirects for administrators when enabled
Configure global 404 error handling and plugin options:
Choose Behavior:
- Show custom message (default): Display a custom HTML message on the error page
- Redirect to another page: Automatically redirect users to a different URL
Disable Redirect for Administrators:
- Checkbox option (enabled by default)
- When enabled, administrators bypass ALL custom redirects when signed in
- Useful for testing and troubleshooting
Save your settings when done.
Complete server configuration guidance:
- View your custom 404 URL
- Test button: Click to verify 404 tracking is working (opens error page in new tab)
- Server-specific instructions: Expandable sections for Apache, Nginx, and .htaccess
- Copy/paste ready configuration snippets
- Note: Custom redirects work automatically via Moodle's callback system (no special setup needed)
The plugin uses a custom 404 error page (error404.php) that must be configured at your web server level. When a 404 error occurs:
- The web server redirects to the custom error page
- The page logs the error details (URL, referrer, user, IP, user agent, timestamp)
- Based on your settings, it either:
- Redirects to another page, OR
- Displays a custom message
Important: You must configure your web server to use the custom 404 page. See the Setup section below.
All function and variable names follow Moodle's frankenstyle naming convention (prefixed with tool_redirectplus_).
The plugin creates one table: tool_redirectplus_404
| Field | Type | Description |
|---|---|---|
| id | int(10) | Primary key |
| url | text | The URL that generated the 404 error |
| referrer | text | The referrer URL (nullable) |
| userid | int(10) | Foreign key to user table (0 for guests) |
| timecreated | int(10) | Unix timestamp |
| ip | varchar(45) | IP address (supports IPv6) |
| useragent | text | User agent string (nullable) |
Access to the 404 Error Report requires the moodle/site:config capability (site administrators only).
This plugin stores the following user data:
- User ID of who encountered the 404 error
- IP address
- User agent (browser information)
This data is used solely for site administration and debugging purposes. Site administrators should be aware of this when considering privacy policies and GDPR compliance.
404 errors are not being logged:
- Verify server configuration: Use the Test button in the Setup tab
- Check web server config: Ensure ErrorDocument directive is correctly set
- Check file permissions: Make sure
error404.phpis readable by the web server - Check plugin enabled: Go to Settings tab and ensure tracking is enabled
- Database table exists: Verify
tool_redirectplus_404table was created - Enable debugging: Site administration > Development > Debugging (set to DEVELOPER)
- Check logs: Review web server error logs and Moodle logs
Cannot access the plugin:
- Ensure you're logged in as a site administrator
- Verify you have the
moodle/site:configcapability - Look under Site administration > Redirect Plus (in the General section, not Tools)
Custom 404 page not showing:
- Clear your browser cache
- Verify the server configuration is correct
- Check that mod_rewrite (Apache) or similar module is enabled
- Test with a definitely non-existent URL
Performance concerns with large datasets:
- The plugin automatically uses pagination (50 records per page)
- Consider periodically deleting old records using the "Delete All Records" feature
- Records are indexed by
timecreatedanduseridfor optimal query performance
This plugin uses AMD modules for JavaScript. To modify JavaScript files:
- Install Node.js (https://nodejs.org/)
- Install dependencies:
npm install - Edit source files in
amd/src/directory - Build minified versions:
grunt amd
The build process:
- Source files:
amd/src/*.js - Minified output:
amd/build/*.min.js - Grunt automatically minifies and optimizes the code
To watch for changes and auto-build:
grunt watchHelp keep Redirect Plus free and actively maintained!
If this plugin has saved you time or made your Moodle site better, please consider showing your appreciation:
Your support helps fund:
- ✨ New features and improvements
- 🐛 Bug fixes and maintenance
- 📚 Documentation and tutorials
- 💬 Community support
- ⚡ Faster response times
Every contribution matters - thank you! 🙏
For bug reports and feature requests, please visit our issue tracker: 👉 Report an Issue on GitHub
For other inquiries, please contact:
- Email: support@gwizit.com
- Copyright: 2025 G Wiz IT Solutions
- Website: gwizit.com
Copyright 2025 G Wiz IT Solutions support@gwizit.com
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.