Drupal custom URL rewriting - Change the admin url to enhance security
Ads by DZone
The following tip can be used in multiple scenarios (being anywhere you need custom URL rewriting and want to do this without .htaccess), but I'll illustrate it for two specific purposes.
- At our company all urls beginning with
/admin are blocked from outside by a firewall for content security reasons. This sucks, because Drupal administration is done on pages with a/admin url. So we need to find a way to rewrite all of the urls to something like/config (or something else). - If someone knows your site is on Drupal, this gives him some knowledge on how the site is structured. For example does he know that all administration is done on
/admin . To make it harder to guess this url, we want to rename it.
function custom_url_rewrite($op, $result, $path) {
if ($op == 'alias') {
if (preg_match('|^admin(/{0,1}.*)|', $path, $matches)) {
return 'config'. $matches[1];
}
}
if ($op == 'source') {
if (preg_match('|^config(/{0,1}.*)|', $path, $matches)) {
return 'admin'. $matches[1];
}
}
return $result;
}
(1 vote)
- Login or register to post comments
- 1774 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)









