Drupal redirect in .htaccess

Using .htaccess is one of the best ways to redirect a URL to a new URL. Particular care needs to be taken with Drupal sites for it to work correctly.

The following snippets needs to be added to the root .htaccess file directly after the following lines:

  1. # Various rewrite rules.
  2. <IfModule mod_rewrite.c>
  3. RewriteEngine on
  4. .......
  5. # If your site is running in a VirtualDocumentRoot at http://example.com/,
  6. # uncomment the following line:
  7. # RewriteBase /
  1. #custom redirectsRewriteRule ^oldpath$ http://www.example.com/newpath [R=301,L]
  2. #end custom redirects

More info on Ping Vision

If you liked this, you'll love my book, Master Drupal Module Development.

"..the must have drupal developers book"

Feeling stuck with Drupal 8 module dev?

Get the free 7 lesson course that will help you get started today without feeling overwhelmed.

  • Create Drupal modules with just a few commands using the Drupal Console
  • Create custom pages
  • Create custom blocks
  • Create admin forms
  • Demystify routers and controllers
  • Bonus material

Find out more

Add new comment