Yireo - Extensions, tutorials and blog for Magento and Joomla!

Blog Tags

MageBridge Standard

Forcing redirects for usage with Dynamic404

Tuesday, 04 January 2011

Once in a while we receive questions on our Dynamic404 component, when it fails to redirect a certain URL. But when diving into this suspected bug, it's actually not a bug at all: The used URL actually does not generate a 404 Not Found error, and therefor Dynamic404 is not put into play. It made us wonder if we could still solve it.

To generate a 404

Dynamic404 is aimed to turn 404 errors into actual redirects, so to never confront your visitors with ugly 404 pages. For those that prefer still to have 404 pages, Dynamic404 enhances the default 404 page by showing a list of possible matches that a visitor can click on. This functionality is wonderful and works pretty well.

But Dynamic404 is not your perfect redirect tool: It only does something when something already went wrong. The manual Dynamic404 rules however suggest that you can redirect a certain URL to something else, even if that URL is still in use - and that's not true. Instead of modifying the Dynamic404 functionality (which would also require a complete rebranding to something like DynamicRedirect), we were wondering how to generate a 404 error manually: This would bypass the whole problem, because any 404 is picked up by Dynamic404 again.

Put it in htaccess

The htaccess-file allows for neat tricks with the Apache mod_rewrite module: This allows you to redirect something to something else. It works in more or less the same way as Dynamic404 itself, except that Dynamic404 is a lot easier. Now, using the htaccess-file you can create a manual redirect for all your old Sobi2-pages for instance, by adding the following:

RewriteCond %{THE_REQUEST} some-old-links\?sobi2Task [NC]
RewriteRule ^([^/]+)/?$ /index.php/component/com_dynamic404/ [R,L]

The first line is completely up to you and depends your actual site URLs, but the second rule can be just copied without thinking. The first rule matches certain URLs and redirects them to the Dynamic404 component. It actually does not involve a 404 error at all, but still allows the Dynamic404 engine to fire up some kind of ruling. Very cool stuff, once you get the hang of it.

About Yireo

Yireo tries to help webdevelopers build successful Joomla! and Magento sites.

More about Yireo