Creating Custom Content Handlers
Using content handlers you can redirect a request to a TContentBase descendant class. This class is responsible for providing the actual content of the response. Content handlers are not components. They are lightweight classes and should be created at runtime.
Creating a new TContentHandler
Creating a new TContentHandler class is very simple. This how-to will show you how to create a new content handler to respond with a XML document.
'The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing.
1) Create a new IntraWeb Stand Alone server using the IntraWeb project wizard. Then create a new unit, name it IW.Content.XML and add this code to it:
3) Still in your ServerController unit, add this code to the initialization section:
4) Now build and run your application. Open your browser and type this URL: http://127.0.0.1:8888/GiveMeSomeXML (note that the port may differ). You will see something like that:
How-To explained
First, we created a new TContentBase descendant class. Every custom content handler must descend from this class. Inside the Create() method, we must set mFileMustExist to FALSE. When TRUE, the TContentBase.Execute() method will search for this file and if it is not found, will reply with HTTP code 404.
Then, all we have to do here is override the TContentBase.Execute() method, and write directly to the aReply object instance. The first thing we did was setting the aReply.ContentType property. This actually changes the Content-Type HTTP header field in our response. In this case, we want to reply with a real XML (and not a XML string inside a HTML), so we use one of the predefined constants in IWMimeTypes unit.
Then, we write a XML directly to the aReply instance, using one of its methods, and we are done.
More…
How powerful is that? You can create TContentBase descendants to handle any kind of request. You can also create an Indy client to post requests to your IntraWeb application implementing a custom protocol and messaging system. The possibilities are infinite.
Starting in IntraWeb 14.0.13, you can also use content handlers to respond to Search Engine requests. If you have an IntraWeb application visible to the internet, web crawlers like googlebot will certainly visit your application. When a web crawler posts a request to your IntraWeb application, you may use a content handler to respond with the content you want to be indexed. In this case, you should set the following ServerController properties:
Demo
A fully functional demo containing this code can be found in our GitHub repository.
Description
Easily redirect WordPress 404 error pages to the homepage or any another page. Plugin supports both permanent redirects (HTTP response status code 301) and temporary redirects (HTTP response status code 302). Plugin will start redirecting 404 error pages to the homepage as soon as you activate it by using the 301 permanent redirect. To configure it open Dashboard -> Settings -> General Settings and scroll down to the bottom.
Please note that permalinks have to be enabled in Dashboard -> Settings -> Permalinks in order for the 404 Redirect to work properly.
New Feature: 404 errors can be logged with this plugin so you can examine what pages may be missing.
Redirect 404 Error Page is very useful for themes that have an ugly, uninformative 404 server error page that can’t be changed without messing with code and set to still return 404. Simply create a new custom 404 error page and activate the plugin – problem solved!
It’s also very useful in situations when a lot of content has been removed from the site. For those situations create a new page explaining what happened and simply configure Redirect 404 to use that page.
It’s also very useful in situations when a lot of content has been removed from the site. For those situations create a new page explaining what happened and simply configure Redirect 404 to use that page.
This is an ideal plugin for missing page redirection.
Installation
Follow the standard procedure:
- Upload the unzipped plugin folder to the
/wp-content/plugins/
directory or install the plugin from Dashboard -> Plugins -> Add New - Activate the plugin through the Plugins menu
- Head to Dashboard -> Settings -> Redirect 404 Settings to configure it
FAQ
Did you activate the plugin? And enable the permalinks? Still doesn’t work? Sorry to hear that. Please head over to the support forum and open a new thread. We’ll help you out ASAP.
Reviews
If you are looking for a lightweight simple plugin to sort out your 404 errors then this is the plugin you need. Very easy to use and no skills are required to set it up. Thank you