How can I avoid direct access to codeigniter controllers, rather than routes?

When we are defining all your URLs through the routes.php file, the direct access to your code-igniter class will make accessible duplicated pages for the website. Duplicated pages affect SEO in large extents, so better to avoid direct access to the controller functions.

Step 1: Create a controller function for 404 response page

Create a separate controller and a normal public function in the controller folder. The following code inside the function makes the 404 error response page.

Step 2: Modify your routes.php file

At this point, you already have a good idea about the config/routes.php file, otherwise please have a look at: Documentation for Codeigniter Routes. The routes.php will be similar to the below code after modification:

There are mainly two points in your routes files:

  1. Overwrite your default 404 error page with defined controller page:  $route['404_override'] = 'errors/show_404';
  2. After defining all your routes, avoid further URL access by pointing all other URLs to the 404 controller page written before:  $route['(:any)'] = 'errors/show_404';

So, pointing all requests to the 404 page after parsing all valid routes will help you to avoid direct access to the controller with controller name and its method names.

Sending Push Notification in Drupal with your plugin

It is difficult to implement even simple features in Drupal. Luckily Drupal is one of the CMS which have the largest number of plugins (modules). For implementing push notification feature, there are some good plugins available. We are selecting one plugin from the module gallery and will try to implement the push notification feature for our custom developed module.

Drupal’s “Push Notifications” Module

The module “Push Notifications” will help us to do the push notifications and device registrations for us. You can find and download the module at Drupal website. The module supports:

  1. Apple Push Notification Service (APNS)
  2. Google Cloud Messaging (GCM) and
  3. Cloud 2 Device Messaging (C2DM).

 How to Implement Push Notification Module?

Login to your admin panel and install your module. Follow the steps given below:

  1. Login to your admin panel.
  2. Go to your admin page:
  3. In the field “Install from a URL”, use the following URL: (you can find the latest version from the module page).
  4. Click on “Install” button.
  5. If everything works fine, you will get a message like “Installation was completed successfully.”
  6. Click on the “Enable newly added modules” link to go to the modules listing page.
  7. Go down to the page to see the “Push Notifications” plugins under “Others” category.
  8. Check the enabled column and save the configurations. Your push notification module is enabled now.
  9. Add the certificates and key in the page: Configuration > Web Serivces > Push Notifications > Configuration. For APNS certificate, click on “Generate new certificate string” button, rename your certificates to the displayed names and upload to the sites/all/modules/push_notifications/certificates folder.
  10. After saving your settings, you can test messages to the registered devices from “Send Push” tab.

Configure your module to add the dependency

Since your module is going to use push_notifications module, you have to add dependency for the module. The push_notifications module itself is dependent to the  services, so your module is dependent to both services and push_notifications. After adding dependency, your module info file will look like:

Send Push Notifications from your custom module

Now you can use the push_notifications module to send messages from your custom module. The below example will send a message to the node user when someone comments on the node.

There are many other useful functions in the push_notifications module. You can find more details about the module in our article: Drupal Push Notifications Module’s Functions List (API Manuel).