index.php randomly appears in friendly URLs

Created on 23 April 2019, over 5 years ago
Updated 12 February 2023, almost 2 years ago

Problem/Motivation

Intermittently, index.php appears in our friendly URLs and it's always in the same spot, right after the first slash like it would be if you weren't using friendly URLs. Example: www.marshall.usc.edu/index.php/some/pattern/page.

This is reported to happen on both apache and nginx.

Steps to reproduce

One way to replicate was posted by marcaddeo in #2642126-13: [regression] Rewriting allows index.php/foo/bar URLs to function

  1. Using drush, clear the cache. drush @site.alias cr
  2. Immediately go to http://your.site.com/index.php
  3. Hover over any menu links, they will now have index.php prefixed on all of them, e.g. /index.php/user/1
  4. Go to http://your.site.com/
  5. All cached generated links will still be prefixed with /index.php/, e.g. /index.php/user/1

Proposed resolution

TBA

Remaining tasks

TBA

User interface changes

API changes

Data model changes

Release notes snippet

Original Issue Summary
Please note that this issue affects more than one version of Drupal, and my selection of the path.module was only a guess at what might be responsible. It might be noteworthy to mention that we are using the Pathauto module.

Intermittently, index.php appears in our friendly URLs and it's always in the same spot, right after the first slash like it would be if you weren't using friendly URLs. Example: www.marshall.usc.edu/index.php/some/pattern/page

After much research I found that our site is not the only site experiencing this issue but no one seems to know exactly what causes it. From the threads I've been reading, there is speculation that the bug may not be in core itself, that it may be introduced by one or more modules. But in our case we're either not using one of the speculated modules, or disabling it didn't solve the issue.

Hence the reason I am creating this Issue Report. I don't think anyone would ever want /index.php/ included in their friendly URLs, so why not just add some code to core to make sure it doesn't do that, ever!!

What are the steps required to reproduce the bug?
Unknown

What behavior were you expecting?
/index.php/ should never be included in a URL path when friendly URLs and Pathauto are being used.

What happened instead?
I think we covered that.

Please include as much information as you can:
OS: nginx
webserver name and version: Unknown (this happens on sites on Platform.sh and Acquia though, for what that is worth)
PHP version: 7.X
Drupal version: We are on the latest release of 8, but I read threads of it happening on 7 too.
Drupal path: site (web) root
Everything else you might feel is relevant:
I provided everything I can think of, but I'd be happen to answer any questions that might help.

🐛 Bug report
Status

Active

Version

10.1

Component
Path 

Last updated 2 days ago

  • Maintained by
  • 🇬🇧United Kingdom @catch
Created by

🇺🇸United States rick_p

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy senzaesclusiva

    Hello @amavi and @thomaswalther, sorry to reopen the post.
    I have since a few days, in an Apache platform, the same problem of index.php in the URLs, which also branches to all the menu links.
    For more information, I found "index.php" matches in only two db tables: 'local_location (63 records)' and "batch (1 record)".

    The local version of the site does not have this behavior.

    I would like to try your code to get rid of the problem, but in Drupal 9.4.8 I don't have "RewriteEngine" in settings.php as per your indication, while I have it in the .htaccess file (RewriteEngine on)
    How can I do it...can I still copy it into settings.php?

    Thank you very much if you can give me any pointers

  • leymannx Berlin

    To fix this, install the Redirect module , go to /admin/config/search/redirect/settings and activate "Enforce clean and canonical URLs".

  • leymannx Berlin

    The fix actually is really bad if you rely on multiple aliases for one entity. 😬

    Nonetheless the bug suddenly disappeared after I enabled that option and then disabled it again, flush cache. 🧐

  • 🇮🇹Italy senzaesclusiva

    You are correct. I installed and enabled the Redirect module with the settings you reported and the index.php string disappeared.
    Later, after doing the update to D 9.5.4 and then D 9.5.5 I first disabled the feature and then uninstalled the module, and now index.php no longer appears.

    I am still left with, in the tables 'locales_location' and 'batch' the old references with the advice 'Version of Drupal where the location was found'.
    I'm trying to figure out if I can empty these two tables without creating any operational problems.
    Thank you very much for your advice

  • We solved this issue installing and configuring the HTTPS and WWW Redirect module https://www.drupal.org/project/httpswww
    In addition to solving the index.php problem, it also redirects www and http which allows you to always have one session open and not several for registered users.

  • 🇮🇹Italy senzaesclusiva

    Hi @Jorgefernandes,
    thanks for your suggestion. At the moment the problem seems to be gone after an update, but this module looks interesting for other functions as well.
    Thanks again

  • 🇪🇪Estonia veskimees

    It's still here! & #5 seems to work.

    Drupal 9.5.9, PHP 8.0.28, DB 10.6.13-MariaD8-log
    From D7 upgraded site, some 2000 nodes, lot of different modules.
    Had different pictures in different tabs in same browser window.
    There was pseudomenu made with View, in v.1 headings were w 'index.pxp' (and some messed up), in v.2 without.

  • 🇮🇪Ireland b0gucki3 Limerick

    #49 worked for me. Many thanks!

  • 🇩🇪Germany mkalkbrenner 🇩🇪

    We're also affected by this issue but want to avoid additional modules as workaround. Therefore, we adjusted .htaccess to let apache perform the redirect.

    I think we should raise the priority of this issue. Even if drupal is able to deliver /index.php/node/27, all requests to /index.php/sites/default/files/* return 404 Page not found!

  • 🇩🇪Germany mkalkbrenner 🇩🇪

    Here's a patch that could be included in composer patches.

  • last update about 1 year ago
    30,334 pass, 1 fail
  • 🇦🇹Austria drupalfan2

    Added patch #57 to composer.json
    and this helped me to solve the problem at downloading files from /sites/default/files folder (page not found error for urls like /index.php/sites/default/files/filex.pdf).

  • Hi :)

    At my .htaacces the last Line is red with Visual Studio Code:

    # Pass all requests not referring directly to files in the filesystem to
    # index.php.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !=/favicon.ico
    RewriteRule ^ index.php [L]

    So I put favicon Line in comment and Line with index.php (last line) become normaly, good Idea???

    # Pass all requests not referring directly to files in the filesystem to
    # index.php.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # RewriteCond %{REQUEST_URI} !=/favicon.ico
    RewriteRule ^ index.php [L]

  • 🇬🇧United Kingdom 2dareis2do

    I have had this issue with a couple of sites now. i.e. index.php showing on Plesk web-server with being served with both Apache and Nginx. As soon as redirect module is enabled the 'index.php' part of the url goes away.

    Erratic.

    #57 looks interesting.

    (On plesk, favicon.ico is also used/loaded from admin ui when available now. see https://docs.plesk.com/release-notes/obsidian/change-log/#plesk-18057)

  • First commit to issue fork.
  • 🇺🇸United States ddavisboxleitner

    I have come up with an initial and unsophisticated solution to the problem. In the UrlGenerator class (core/lib/Drupal/Core/Routing/UrlGenerator.php).

    On line 364 we see the following:
    $base_url = $this->context->getBaseUrl();

    When a user requests the homepage using 'www.yoursite.com/index.php' we are getting '/index.php' as the base URL. This is a special case where we are on the homepage and we can safely disregard this base URL. The unsophisticated solution is to simply empty this $base_url variable.

    if ($base_url === '/index.php') {
          $base_url = '';
    }
    

    There may be a smarter way to handle this special case. For now, this code will prevent the bug from appearing.

  • Pipeline finished with Failed
    8 months ago
    Total: 528s
    #168231
  • I put this on my Robot.txt :

    /index.php/*

    And on the module "Path Auto" I check/Uncheck the option User and problem seem stop.... Strange...

  • 🇫🇷France floown

    Hello,

    I have randomly the same problem.

    Will there be a backport to Drupal 10 latest?

    Regards

  • 🇨🇦Canada Liam Morland Ontario, CA 🇨🇦

    @ddavisboxleitner I don't think that solution would work if the Drupal site is not at the root of the host, for example, www.yoursite.com/SITE/PATH/index.php.

Production build 0.71.5 2024