[Drupal] How to redirect Traffic from Existing Drupal page to another URL
We had an issue pointed out by one of our Drupal client that traffic from specific page to be redirected to another URL. In Drupal redirecting trafic from specific page on specific domains can be handle either by including a Drupal hook_init function or setting the .htaccess. Function hook_init runs at beginning of page request but it loads all Drupal modules and database for every page which results in performance issues. On the other hand .htaccess files are read on every page request and the effect to the changes in the .htaccess files is quick.
For sample,if there exists a purpose to change URL alias name and to make it a user friendly name and at the same time traffic to the old links are to be redirected to the new URL.
- change the old redirect URL to a dummy name and unpublished the same.
- Next change the new URL name setting a user friendly alias name and set it published.
- At last set .htaccess to the urls ,so that the old URL redirects also response the new URL page in site.
Place the code below in the .htaccess file.
RewriteBase / RewriteRule ^old-URL-name$ new-URL-name [R=301,L]
Always while ensuring traffic from older links to newer,setting .htaccess is most appropriate for stable performance in web domains.