By default, Drupal core does not redirect the home page node path to the home page. E.g. I configure the home page to be "node/1". I can still visit node/1. This makes sense, because Drupal also includes a canonical link to the to node, thanks to NodeViewBuilder.
I.e. in the html head:

<link rel="canonical" href="/node/1" />

After installing redirect module, visiting my home page E.g. example.com, will give me the canonical link as above. Now if I'm a search engine, I'll try to follow the canonical link... visit example.com/node/1 and I get served a redirect to example.com. Argh. This is essentially a redirect loop. Obviously not all search engines care, but for example in my case, Google Search Appliance with follow canonical links enabled is dying and not indexing any Drupal content.

Ideally I'd like to see an option to disable redirects for content set to be the home page - to avoid this particular problem.

Issue fork redirect-2948211

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pingers created an issue. See original summary.

pingers’s picture

Here's a terrible patch, which fixes the use case for me ... but doesn't provide the option.

I tried adding the path matcher service to the RedirectChecker, but this caused more problems...
The path matcher isFrontPage() method ran too early in the request, so it caches FALSE (because routeMatch->getRouteName() returns null), when it is in fact the front page path. Grrr.

Hope this helps someone... and maybe one day I'll get around to rolling a better patch. Sorry.

pingers’s picture

I should probably mention I also went down the road of #1255092: Return "/" instead of the internal path when asked for the URL of the frontpage overriding the url generator service. This caused more problems for me by breaking front page detection.

pifagor’s picture

Status: Active » Needs work

the patch does not go through automatic testing.

pingers’s picture

I'm not sure the patch is actually something maintainers will want to merge... it's more that I had a project requirement to do it.

If we want it in, I'll happily refactor the tests.

vj’s picture

Category: Feature request » Bug report
Status: Needs work » Needs review
StatusFileSize
new1.29 KB

Faced this issue with vanilla Drupal installation and redirect module.

Steps to reproduce.

  1. Install Drupal & redirect module.
  2. Create node with url alias "home" & set default home page to "home" admin/config/system/site-information
  3. Export config using drush cex
  4. Go to homepage domain.com it stays on domain.com
  5. Change front: /home in system.site.yml & run drush cim
  6. Go to homepage domain.com it redirects to domain.com/home

Status: Needs review » Needs work

The last submitted patch, 6: fix_front_page-2948211-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

berdir’s picture

That seems like the opposite of what is talked about there. And might "just" be a cache problem? IMHO, the metadata on the frontpage should *not* point to node/1. With metatag, you can already configure it like that and I think it would make sense to do that by default.

vj’s picture

@Berdir
For me canonical link is not an issue. Its same with and without redirect module.
<link rel="canonical" href="http://drupalvm.test/home" />

My issue is related to redirect from domain.com to domain.com/home. Which is happening due to $this->pathMatcher->isFrontPage() in src/EventSubscriber/RouteNormalizerRequestSubscriber.php returns false on frontpage.

Steps to reproduce.

  1. Install Drupal & redirect module.
  2. Create node with url alias "home" & set default home page to "home" admin/config/system/site-information
  3. Export config using drush cex
  4. front: /node/1 in system.site.yml
  5. Go to homepage domain.com it stays on domain.com
  6. Change front: /home in system.site.yml & run drush cim
  7. Go to homepage domain.com it redirects to domain.com/home

Its more of core bug which fails to detect frontpage with above steps hence redirect module fails for me.
Issue to drupal core : https://www.drupal.org/project/drupal/issues/1503146

Let me know your thoughts, any way to avoid redirect from domain.com to domain.com/home

pratip.ghosh’s picture

StatusFileSize
new4.17 KB

Modified patch with dependency injections.

ryan.ryan’s picture

Patch does apply cleanly and resolves the issue of the homepage redirecting to the canonical URL. I'll report back if there's any undesirable side effects.

komlenic’s picture

Status: Needs work » Reviewed & tested by the community

Confirming that patch resolves this issue with no observed issues.

If nothing else it seems this should be moved to "Needs review" but I'm bumping to RTBC for now.

Liam Morland made their first commit to this issue’s fork.

liam morland’s picture

Created merge request with patch #11.

bradjones1’s picture

Status: Reviewed & tested by the community » Needs work

Looks like a few easy-ish issues with test constructors.

liam morland’s picture

The problem is that in RouteNormalizerRequestSubscriberTest::getSubscriber(), a new RouteNormalizerRequestSubscriber object is created and when that happens, only four parameters are send in to the constructor. The two new parameters, $path_current and $path_alias_manager, are missing.

lily.yan’s picture

StatusFileSize
new4.06 KB

Rerolled fix_front_page-2948211-11.patch in comment#11 based on 8.x-1.8

morbus iff’s picture

#19 works for me.

amateescu’s picture

Note that there's also a core patch dealing with this problem: #1503146: Aliased paths cannot be set as front page

+++ b/src/EventSubscriber/RouteNormalizerRequestSubscriber.php
@@ -97,7 +123,16 @@ class RouteNormalizerRequestSubscriber implements EventSubscriberInterface {
+      $front_alias = $this->pathAliasManager->getAliasByPath($front_uri);
+      $current_alias = $this->pathAliasManager->getAliasByPath($current_path);

This will run path alias processing before routing is done (i.e. before \Drupal\path_alias\EventSubscriber\PathAliasSubscriber::onKernelController()), and will disable core's pre-loading optimization. See #2508217-14: AliasManager should use the current route match for outbound alias pre-loading cache keys for details.

weekbeforenext made their first commit to this issue’s fork.

weekbeforenext’s picture

I resolved merge conflicts with the MR.

vadim.hirbu made their first commit to this issue’s fork.