1

We are running a Drupal 8 site with 400 or so pages of content.

We have a number of "resource pages" were views generate links to content by topic area. Here is an example of one of those pages.

In general everything is working as intended, however, sporadically we have an issue with clean URLs and the link to content in those views. Specifically, index.php is added to the link presented only to anonymous users. For example, website/mypage becomes website/index.php/mypage, or even website/index.php/index.php/mypage.

This problem never occurs for logged in users, only anonymous users. It is also not consistent. It may happen to 2-3 of the links in a single view, or several across the views on the same page but generally will not affect the entire site or page. It may not happen for weeks and then 4-5 times in 24 hours. In the last few days it appears to be happening every few hours.

It appears to mostly only happen on resource pages (they are a content type) like the one I linked above. We have also some times observed it occurring on other menu links. These links usually still work however...

We have been unable to find a reason for it. Clearing the site cache a few times does fix the issue but it is somewhat unacceptable that this happens regularly.

The views on those specific pages do make use of relationships and aggregation to generate their content. Several also use re-write rules to generate custom link text. The issue appears to affect both types of views on those pages.

Can anyone suggest what the cause of such an issue could be or give any ideas as to how to stop it occurring?

1
  • I would have said rebuild permissions, but did you customise the .htaccess file? Grab a fresh copy and see if that works. There are also minor changes for 'virtualdocumentroot' in there if that is how you are running your web server. The redirect 'smells like' an apache configuration thing.
    – Interlated
    Commented Jul 11, 2017 at 3:49

1 Answer 1

4
+50

How this gets started is hard to tell. But once it does it spreads quickly. When a user clicks on a link with /index.php the page will include /index.php in the base url, which then is used for all links generated on this page. The same is the case for search bots, once they hit a link with /index.php they will crawl the whole site with it.

To stop this, redirect the unclean urls. You could use this core patch or Redirect, but as long as the core patch is not committed and the module is not released, you can do this in .htaccess. Place these two lines at the top of the rewrite rules:

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteCond %{THE_REQUEST} "^[A-Z]{3,9}\ /index\.php(.+)\sHTTP" [NC]
  RewriteRule "^" "%1" [R=301,NE,L]
8
  • Are you implying there could be a link somewhere on the site hard coded with index.php which propagates through the base_url or it is being dynamically created either in core or from some module?
    – tanbog
    Commented Jul 11, 2017 at 23:51
  • No, it's not so simple as a hard coded link. The typical behavior is very erratic like you described it. It is not necessarily inside of drupal, could be someone from the outside who tries to access the site with /index.php. I never had enough data to find a pattern how this starts. Are you able to investigate this in the logs?
    – 4uk4
    Commented Jul 12, 2017 at 6:36
  • Apache logs? sure, we have a bunch. What should I be looking for? There are some get requests to the incorrect urls from crawlers.
    – tanbog
    Commented Jul 12, 2017 at 6:48
  • interesting would be if there is a pattern how this starts, which url is the first with index.php and who requests it
    – 4uk4
    Commented Jul 12, 2017 at 6:53
  • 1
    It may not be the root cause, but now this spider has the wrong url's and will try them again and again. Only chance is to use one of the methods I've described for a 301 redirect to tell him to use the correct ones.
    – 4uk4
    Commented Jul 12, 2017 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.