Drupal URL Redirect: A Comprehensive Guide

Author

Reads 1.3K

YouTube Website on Laptop Screen
Credit: pexels.com, YouTube Website on Laptop Screen

Redirecting URLs in Drupal can be a bit tricky, but it's a crucial task for maintaining a smooth user experience.

You can use the Path Redirect module to redirect URLs from one path to another, making it easy to update URLs without affecting existing links.

To set up a redirect, you'll need to configure the Path Redirect module to match the old URL pattern and redirect it to the new URL.

The module allows you to specify a destination URL, a redirect method, and even a custom message for the user.

Understanding URL Redirects

URL redirects are a crucial aspect of Drupal, allowing you to change the URL of a page without affecting its content.

A 301 redirect is a permanent redirect that tells search engines to update their index and send users to the new URL. This type of redirect is ideal for migrating content to a new location.

In Drupal, you can create a 301 redirect using the Redirect module, which is a built-in feature. This module makes it easy to set up redirects without requiring any coding knowledge.

Credit: youtube.com, Drupal 7 Redirect Module - Daily Dose of Drupal Episode 8

A 302 redirect, on the other hand, is a temporary redirect that doesn't update the search engine index. This type of redirect is useful for testing or maintenance purposes.

Drupal's Redirect module allows you to create redirects based on the URL path, query string, or HTTP referrer. This flexibility makes it easy to set up redirects for complex use cases.

You can also use the Redirect module to create redirects for specific user roles or IP addresses. This feature is useful for creating redirects for specific groups of users or for testing purposes.

For another approach, see: Webflow Redirects

Using the Redirect Module

The Redirect module is a user-friendly tool that allows you to create manual redirects from one URL to another in Drupal. It's a contributed module that comes as a package of three submodules: Redirect, Redirect 404, and Redirect domain.

To use the Redirect module, navigate to the Configuration — Search and metadata — Redirect page, where you'll find a simple interface to create redirects. You can filter redirects by source, destination, status code, and original language, making it easy to find and edit existing redirects.

Credit: youtube.com, Cool Drupal 7 Modules #5 - Redirect Module

To add a new redirect, hit the "Add redirect" button and enter the source URL, destination URL, and status code. The default status code is 301, which is recommended, but you can change it on the Settings tab if needed. Be aware that the status code greatly affects SEO, so choose wisely.

Consider reading: Google Add Url Website

Why Redirect a Website URL

Redirecting a website URL is a crucial step in maintaining a clean and SEO-friendly website. A 404 "Not found" error can be frustrating for visitors who arrive at a page that no longer exists, especially if they've saved bookmarks or shared links.

According to Moz, 301 redirects pass between 90-99% of link equity to the new URL, ensuring you don't lose previous SEO efforts.

Redirects are essential in situations like moving to a new domain, forwarding multiple domains to a single one, or fixing a mistake or typo in a URL. This helps prevent confusion for both search engines and users.

Credit: youtube.com, IIS Redirect Feature to show another page

Here are some common scenarios where redirects are necessary:

  • Moving to a new domain
  • Forwarding multiple domains to a single one
  • Fixing a mistake or typo in a URL
  • Saving a situation where a wrong URL has been shared with many people

Redirects also help inform search engines about the new official address, allowing the new URL to inherit the SEO achievements of the old page. This is especially important for SEO, as it can improve session duration and reduce bounce rates.

How to Use the Redirect Module

The Redirect module is a powerful tool for Drupal sites, allowing you to create manual redirects from one URL to another with ease.

To get started, you'll need to enable the Redirect module, which comes with three submodules: Redirect, Redirect 404, and Redirect domain. These submodules provide additional functionality, such as logging 404 errors and performing redirects between different domains.

The main module provides a simple interface that makes it easy to do 301 redirects and more, even for non-tech savvy users. You can find the module settings panel by going to Configuration → Search and Metadata → URL Redirects.

Credit: youtube.com, Why to Use the Redirect Module

To add a new redirect, select "+ Add redirect" and then fill in the necessary information, including the source URL, destination URL, HTTP code, and language. The default status is 301, which is recommended, but you can change it on the Settings tab if needed.

Here are the seven available HTTP codes that you can use for redirects:

To edit or delete a redirect, select Edit or Delete from the Operations menu, or select multiple redirect items checkboxes and select Delete redirect from the listing view menu. Note that deletions cannot be undone.

When you're done, you can save the redirect by selecting Save.

Redirect Module Features

The Redirect module is a powerful tool for creating URL redirects within Drupal. It's a contributed module that comes as a package of three submodules: Redirect, Redirect 404, and Redirect domain.

The module allows you to easily create manual redirects from one URL to another and maintain a canonical URL for all content. You can find the module settings panel by going to Configuration → Search and Metadata → URL Redirects.

Credit: youtube.com, How to redirect a URL to another URL. Redirect Drupal module

The Redirect module has plenty of capabilities that developers love it for, including Views API integration, integration with Drupal's page cache for performance optimization, redirect counter, automatic cleanup of inactive redirects, and much more.

You can add redirects by hitting the "Add redirect" button and entering the source URL, destination URL, and status (from 301 to 307). The default status is 301, which is recommended, but you can change it on the Settings tab if needed.

Here are the available HTTP status codes for redirects:

The Redirect module can team up with the Pathauto module to automatically generate path redirects and make sure the URL changes do not break the existing links.

Troubleshooting Redirects

Redirects can be frustrating, especially if they're not working as expected.

A common issue with redirects is that they can be set up incorrectly, resulting in a "too many redirects" error. This can happen when a redirect is set up to point to another redirect, creating an infinite loop.

To troubleshoot redirects, it's essential to check the Drupal URL redirect settings, specifically the "Redirect path" field. This field should contain the exact URL you want to redirect to, including any query parameters.

Not Following Front Page URL

Credit: youtube.com, Fix - Page with REDIRECT in Google Search Console [SOLVED]

If you're using the Redirect module and setting the front page to a specific URL, but the redirects aren't following it, you're not alone.

The issue is often caused by the module treating the URL as case sensitive, as seen in Example 2. In this case, the referring URL was http://www.example.com/when-to-go/october, but the redirect was pointing to http://www.example.com/en-us, which resulted in a "The page isn't redirecting properly" error.

To fix this, make sure to use the correct URL case, and also ensure that the front page is set correctly in the General site settings.

Here are some common issues that can cause redirects to not follow the front page URL:

  • Incorrect URL case
  • Front page URL not set correctly in General site settings

By addressing these issues, you should be able to get your redirects working as expected and sending users to the correct page.

Don't Redirect

Redirecting within a hook or service can interrupt the flow of the page request for other parts of your site.

Credit: youtube.com, 😎 Cool Tool Tuesday #3 - Redirection Checker - Solving 301 Redirect Issues

It's generally a bad idea to redirect within a hook or service because you can interrupt the flow of the page request for other parts of your site.

You should be looking at redirecting in a form submission handler or subscribing to an event and redirecting from there.

If you want to redirect a form submission for a form that you don't have control over, you'll need to use a hook_form_alter() to alter the form to add a redirection call to the submission of the form.

The type of form being altered will dictate how you add the submission handler to your form, but the general rule of thumb is that if you've added the submit handler to the form and it isn't called, you should swap to the other variant.

This method of redirect will allow the form to complete any tasks it needs before redirecting, which prevents nasty bugs if the form is redirected too early in the processing of submit handlers.

Expand your knowledge: Does Redirecting a Url Affect Seo

Hooks and Services

Credit: youtube.com, 301 Redirects Explained In Under 4 Minutes | Help Your Site's SEO!

Hooks and Services play a crucial role in redirecting in Drupal. They are low-level redirects that don't affect the rest of the system.

You can redirect in hooks and services, but it's not the preferred method. This is because it can be more complex and might not be the most intuitive way to handle redirects.

The Redirect module provides several hooks that allow you to customize and modify redirects. These hooks include hook_redirect_load(), hook_redirect_load_by_source_alter(), hook_redirect_prepare(), and hook_redirect_alter().

Here's a breakdown of what each hook does:

  • hook_redirect_load() - adds new items to an array of redirects
  • hook_redirect_load_by_source_alter() - modifies redirections for a given source address
  • hook_redirect_prepare() - changes the form of a redirection in the module's administration panel
  • hook_redirect_alter() - changes the settings of a redirect just before it is triggered

It's worth noting that the Redirect module works well with the Pathauto module, creating a harmonious tandem for managing redirects when changing page aliases.

Redirect Module Configuration

The Redirect Module Configuration page is where all your redirects will be stored. From here, you can easily find the necessary ones through filtering, by source, destination, status code, and original language.

You can edit or delete redirects from this page. To add a new redirect, hit the "Add redirect" button and enter the details: the source URL, the destination URL, and the status (from 301 to 307).

Credit: youtube.com, Install and Config Module Redirect

The default status is 301, which is recommended, but you can change it on the Settings tab if needed. This is where the Redirect module's capabilities shine, offering a user-friendly interface for non-tech savvy users.

You'll find the following submodules within the Redirect module: Redirect, Redirect 404, and Redirect domain. Each of these submodules provides a specific function, making it easy to find the right tool for the job.

Here are the three submodules and their functions:

  • Redirect: Allows you to redirect a website URL to another one.
  • Redirect 404: Logs 404 errors and allows you to create a redirect for these pages.
  • Redirect domain: Allows you to perform a redirect between different domains.

Frequently Asked Questions

What is the difference between redirect and forward URL?

Redirects occur on the client-side, changing the browser's URL, while forwards happen server-side, returning a result to the browser

Leslie Larkin

Senior Writer

Leslie Larkin is a seasoned writer with a passion for crafting engaging content that informs and inspires her audience. With a keen eye for detail and a knack for storytelling, she has established herself as a trusted voice in the digital marketing space. Her expertise has been featured in various articles, including "Virginia Digital Marketing Experts," a series that showcases the latest trends and strategies in online marketing.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.