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