[Drupal] How to alter urls in a Drupal 6 website?

| | 1 min read

One of our Drupal sites we had worked on required us to implement region based content filtering and it was to be done through a value stored in a session. The Drupal site was also using Boost to enable static page caching. Boost stores pages as HTML files inside a cache folder and each page is served from the cache for anonymous users. To implement the filtering process successfully for anonymous users, we had to find a way to alter the URLs for the selected region. Read on to know how to alter URLs in a Drupal 6 website.

We needed to add a query string for outbound urls like '?region='region_name''. We were looking for a way to do that and we came across a function in the Drupal Core - custom_url_rewrite_outbound() This function is not a hook and it should be placed in the settings.php file to work correctly. Moreover it is available only in the Drupal 6core.

Have a look at how we implemented the function in the settings.php file of our Drupal website

A word of caution. Each and every link in a Drupal website goes through this function and if it is not implemented correctly there is a possibility to make your Drupal site slow.

Hope the article was helpful. Shoot your comments using the comment form below.