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
- Using drush, clear the cache. drush @site.alias cr
- Immediately go to http://your.site.com/index.php
- Hover over any menu links, they will now have index.php prefixed on all of them, e.g. /index.php/user/1
- Go to http://your.site.com/
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #64 | drupale_bug_index.JPG | 83.19 KB | amavi |
| #57 | 3050261_htaccess_scaffold.patch | 731 bytes | mkalkbrenner |
| #56 | 3050261_htaccess.patch | 627 bytes | mkalkbrenner |
| #48 | Screenshot 2023-03-20 at 11.48.05.png | 165.84 KB | norman.lol |
Issue fork drupal-3050261
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
Comment #2
cilefen commentedWould you please reference the links you researched in the issue summary?
I have a feeling there is already a core issue for this but admittedly, I can’t find it.
Comment #3
rick_p commentedI searched and expected to not be the first to report this as well. The links I referred to were not necessarily on Drupal.org and more often than not, they only offer work-arounds and fixes but not what they think the cause is.
This one suggests a possible cause. Coincidentally, we also do this.
https://craftcms.stackexchange.com/questions/14876/when-redirecting-to-h...
This one suggests that it started after enabling simple sitemap module. Contributor says no and may be right about that because we are using this module too, but disabling it didn't make the issue go away. However, we didn't leave it disabled very long, so it might have been residual.
https://www.drupal.org/project/simple_sitemap/issues/2887766
This one points out how random it can be.
https://drupal.stackexchange.com/questions/228893/index-php-appearing-in...
A closely related item in the Drupal issue queue.
https://www.drupal.org/project/drupal/issues/711650
Most of the fixes assume the server is running apache, but we're on Platform.sh, which runs on nginx. This article explains how to fix the problem with a recipe. We are going to use redirect with a yaml configuration file until a patch or release is available. (see at bottom)
https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/
These are most just fixes, many are the same or similar.
https://stackoverflow.com/questions/39562923/how-to-remove-index-php-fro...
https://docs.expressionengine.com/latest/general/remove-index.php.html
https://stackoverflow.com/questions/38093227/how-to-stop-site-showing-in...
https://craftcms.com/guides/removing-index-php-from-urls
This problem is not isolated to Drupal.
https://wordpress.stackexchange.com/questions/105795/remove-index-php-fr...
routes.yaml redirect method:
"https://{default}/":
type: upstream
# This redirect eliminates /index.php/ from randomly appearing in URLs
redirects:
paths:
'^/index\.php/(.*)$':
to: 'https://{default}/$1'
regexp: true
Comment #4
cilefen commentedComment #5
rick_p commentedJust a quick note to let folks know that we installed the Redirect module and enabled Enforce clean and canonical URLs, and haven't had the problem return since (it's been weeks).
Comment #6
DAKSH commentedI'm facing the issue with
D 8.8.5
I have nginx as reverse proxy. Posted about the issue with server configuration https://www.drupal.org/forum/support/post-installation/2020-04-06/solved...
Configuration:
nginx version: nginx/1.16.1
Server version: Apache/2.4.6 (CentOS)
PHP 7.2.29 with fast_cgi
Contributed module:
Adaptive themes
Admin Toolbar
Ctools
FAQ
Pahauto
Token
Metatag
Schema
AMP
Honeypot
XMLSitemap
Even I have tested with fresh D8 installation without an contributed module, it adds index.php in url. IE: mysite.tld/index.php/contact
Comment #7
hazit commentedI had this problem also.
Disabling the Sitemap module worked for me.
See this issue on the possibility of an interaction between the sitemap module and this problem:
https://www.drupal.org/project/sitemap/issues/3145126
Comment #8
hazit commentedComment #10
detpolito commentedThe same issue happened to me before updating the simple_sitemap module to 3.7.0
Comment #11
scm6079 commentedWe are currently seeing this intermittently on a production host. Google search console showed us duplicate content, alerting us to this issue.
This particular site has alpha, beta, stage, and production instances with the same code and a database restore capability where we have been able to confirm that the issue is intermittent. Cache clear and load of pages typically generates clean urls, but on occasion we see the /index.php/ injected at the start of the URL.
Confirming the contents of the problem in the cache:
Checking the cache_page table, I can confirm that Drupal has cached many pages with /index.php/. Additionally, checking the cache_render, there are cached instances of menus with /index.php/. Additionally, twig calls to url('') return the /index.php/ when this occurs.
Running a clear cache, visiting the pages to prime the cache, I now see zero result and url('') no longer returns the /index.php/. There have been no code deployments, nor module changes between runs where the /index.php/ was included vs. ones where it was not.
Further research is necessary.
Comment #12
derherrberger commentedWe also facing the problem that 'index.php' appears randomly in the menus on two D8 websites on completely different servers, but not on dozens of other D8 instances. The 'index.php' URLs caused problems with the facet search, among other things.
It is particularly confusing that one browser (Anon) outputs index.php in the menus, while another browser displays the URLs correctly.
It seams that this issue appears more often when a new browser session has been started.
We activated the redirect module with 'Redirect from non-canonical URLs to the canonical URLs.' enabled, what redirects the 'index.php' paths to it's correct URL. But in the Menus 'index.php' still appears from time to time.
Comment #13
alexpertsi commentedI had the same problem, and I didn't find the solution...
So I write this simple jquery code to be ok... (I know that this is a hack, not the official solution but... finally works)
Comment #14
blacklabel_tom commentedHi,
I found a couple of solutions for me on Platform.sh.
Nginx redirect
Updating my `routes.yml` to have the following redirect rule:
Redirects module
Checking the ' Enforce clean and canonical URLs.' checkbox in the settings had the same affect as above.
Hope this helps someone.
Cheers
Tom
Comment #15
fathershawnI had a client bring the issue as described in #12 to our attention today. Even more puzzling is that in this particular site, all users are logged in. We both browsed the same page at the same time. When I inspected the element, the href was a normal relative clean path. Her href started with /index.php/ before the clean path. Our client was in Windows and could see this in both her browsers, as could our QA lead, also in a Windows browser. The same twig code on another page did not render the mungled href. As reported in this thread, a cache clear cleaned up the page.
It felt like an old episode of Twilight Zone until a colleague found this issue in the issue queue.
Comment #16
andyd328Also present on 9.1.x
Comment #17
drdam commentedHi,
I confirme the "randomly aspect" of the bug.
request confirm the presence of links with "index.php" in URL in caches.
Cleaning cache from back-office change nothing, clearing with "drush cr" works.
But after some time (user trafic ? robot indexation ? ) some URL are cached with index.php.
Edit :
- It seems this affecte only the production (online-public) but not non-production sites (online-private => htaccess & co)
- No reverse proxy on stack (amazon AWS)
Comment #18
drdam commentedComment #19
drdam commentedMore ideas,
on my project, we use robotstxt module instead of "nativ robots.txt file".
Since now, we have not modification between native robots.txt file (from another project) and the version provide by the module.
The change are call to robots.txt url are let an entry on cache_page table.
Adding the fact that the robots.txt file contains indication for some "index.php" files (see below)
so when executing sql request
mysql> select cid, created from cache_page where data like '%/index.php/%' or cid like '%/index.php/%' order by created asc;
Note : cache_page "cid" are the URL called.
in results :
- the call to robot.txt seems call first.
- After came some page with "correct URL" containing some "prefixed" url on data
- And after "cid" containing prefixed url.
I think that some crawlers may generate somme buggy cached page...
robots.txt file :
Note : sitemap no containing bad url ...
Comment #20
thelinhuk commented#5 works for me. Enable Redirect module and in Redirect Module configuration enable "Enforce clean and canonical URLs". Clear varnish cache
Comment #21
tinhxlee commentedGot the same problem with D9, 5# works for me as well.
Comment #22
thomaswalther commentedI have D9.1.2.
From the defined homepage node all normal menu-links (with node reference) have /index.php/normallink.
If I go to a menu-link with an explicit link like "/news" (no reference to node id), I land on this page /news.
From this site /news the other links looks normal without index.php.
So if I am on index.php/xxx links seems correct. If I am on /news it seems that all links have index.php/xxx in the url
I solved it with clearing the complete drupal cache
Comment #23
john.glynn.davies commentedI found Google had been indexing many of my site's pages using the /index.php/some-url structure, which is possibly why I was experiencing this issue more and more on my site... I'm quite not sure how this came to happen since my custom sitemap module doesn't contain any of these URLs.
I found that if you first clear all caches then visit an uncached page url like: /index.php/example-url on a Drupal site, all of the Drupal generated links on that page, like Menu links, will have URLs that also follow the same structure. And even when you visit the correct version of the page eg. /some-url you will find all/some of those corrupted menu/generated page links are still present. I don't know how/why but I'm guessing that these URLs are being cached somehow (although I couldn't find them in any cache bins), but maybe the server is doing that caching?
Also, if you use something like Metatag which adds a canonical link tag the URL that is generated for that will also follow the /index.php/url structure, which is obviously a pretty bad thing because then you have two different page URLs on your site which respond with exactly the same content.
Clearing the cache does fix the URLs, but this doesn't solve the problem from happening again.
Here are the fairly simple steps I used to "fix" it:
RewriteCond %{REQUEST_URI} ^/(index.php/)+(.*)
RewriteRule ^(.*)$ /%2 [L,R=301,END]
I'm no RewriteRule expert, and so no idea if this is a one fix for all, but this worked for me. Perhaps someone with more expertise can suggest a better way? Then maybe there's a consideration to make updates to these files in core. Unless again, I am terribly misinformed!
What do you guys think? Am I off the mark here?
Comment #24
joncjordan commentedI wanted to comment on our experience with this issue. We had a third-party application on our server that when users logged out, would send them back to our Drupal site but with /index.php appended to the URL. Because we had the redirect module set to "Enforce clean and canonical URLs" we never really noticed that the app was sending users to /index.php before redirecting to the base URL. But prior to getting redirected, Drupal kicked off the cron (we don't have crons configured at the server level, and instead we're just using the built-in poor man's cron). So the cron was getting triggered from /index.php/cron/[cron-key]. The issue was noticed in the sitemap.xml, which gets rebuilt on every cron run, where all of our URLs had index.php.
The solution is to prevent the site from being accessed at index.php at the server level.
Comment #26
preciado04 commented#5 Works for me.
I just installed Redirect contributed module on the site.
By default this module has enabled "Enforce clean and canonical URLs." option.
Thanks @rick_p!!
Comment #27
Ariana42 commented#5 works for me with Drupal 9.3.0.
Thank you @rick_p!
Comment #28
ARRC-Drupal-Chick commentedThis issue just popped up on our production site. I checked the caches as shown in #17 and found 425 entries that should not have been found.
Rebuilding the caches with "drush cr" fixed it.
Next week I'll explore the Apache config fix. (I am actually on vacation and was woken up to deal with the issue on our site.)
My configuration:
Comment #29
lomale@bluewin.ch commentedI had the Problem starting from 9.0.0 on, but not constantly. I didn't find a logically reason.
the workaround #5 works for me now with Drupal 9.3.6 as well.
Thank you @rick_p!
Comment #30
monymirzaComment #31
cilefen commentedThis seems to be duplicating another issue.
Comment #33
quietone commentedClosed the following earlier issues as duplicates because this issue has the most discussion
All the duplicates report the random nature of this problem. Clearing cache will 'fix' the problem but it will re-occur.
I am not sure the best component for this, so leaving at path.module.
Comment #34
le72I confirm we have same issues on Drupal 9.4.
Only on prod
Comment #35
amavi commentedi have this Probelm since 4 years with Drupal 8...
hasardous, but no make problem...
But, I migrate on Drupal 9 and index.php is put in link for my image link sometime, and message not found.... xD
I have Sitemap, remove, but no change, I have put the line on setting.php and works for the moment:
RewriteCond %{REQUEST_URI} ^/(index.php/)+(.*)
RewriteRule ^.*$ /%2 [R=301,END]
Add after RewriteEngine, not a the end of file.
i use Pathauto, but people here tell same problem with no module installed, soo, seem to be a problem in Core No? xD
Comment #36
thomaswalther commented@Amavi, thanks but "END" is not working because error:
"RewriteRule: unknown flag 'END'"Instead, I use this:
Comment #38
den tweed commentedAnother report:
We have this too on a 9.3 production site, seems to happen on the same page but inconsistently. The links in question are part of a Views output, the problem only happens for anonymous users and not logged in users.
Neither sitemap (or xml sitemap) or redirect modules have been enabled
A cache rebuild temporarily fixes the problem
Enabling the redirect module with "Enforce clean and canonical URLs." fixes the problem
Comment #39
eugenechechel commentedTry
drush cc renderComment #40
mferanda commenteddrush cc render worked the first time. It's appeared again... I want to say a week after doing the drush cc render. I believe the index.php has been around for a long while now, but it was only recently noticed to cause a problem with private area file downloads. A double index.php is being added to the url for those links. /index.php/index.php
Comment #41
kinmen commentedSome days ago it happened to me too. 2 different websites.
Drupal Version
9.4.3
Server web
Apache
PHP 7.3.25
DB mysql 8.0.26
Drupal Version
9.3.6
Server web
nginx/1.18.0
PHP 7.4.30
MariaDB 10.5.15-MariaDB-0+deb11u1
No drush, no composer on both
I can't remember any operation I did on both websites at the same time, before what happened. Except that I used google search console to check both websites, which I seldom do in a short time range (2 days) but that can't be the reason.
Same situation as in #38. Menus aren't affected.
This is a huge problem for indexing the websites in Google, because there are hundreds of wrong urls and Google complains about it. This obviously affects the website's ranking.
Comment #42
newaytech commentedGot alerted to this from Google Search console. #5 fixed it up for me - thanks all!
Comment #43
zeddgre commented@Amavi and @thomaswalther , your solution saved my life today :-) It seems that the "Redirect" plugin is not available for D8 so it was not an option (this is not clear for me but Redirect branch 8.x apparently needs D9 or D10). I cannot believe that this issue has been ongoing for the last 4 years. Our site was working perfectly until recently when these index.php started to appear randomly ... I cannot point to a specific action that did start the problem, weird.
Pierre
Comment #44
kinmen commented@zedgre Yes, same for me... 2 different websites, same core, different web server, different modules... Randomly crazy.
Comment #46
danchadwick commentedI just experienced this too. Drupal 9.4.8 hosted on platform.sh, multisite. One site did have the redirect module installed and did not experience the issue. The other did not have refresh enabled and did.
drush cc renderdid resolve it, but I don't know if it will recur. I've been on platform.sh for a few years now and it has only happened once.Comment #47
senzaesclusiva commentedHello @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
Comment #48
norman.lolTo fix this, install the Redirect module, go to
/admin/config/search/redirect/settingsand activate "Enforce clean and canonical URLs".---
Comment #49
norman.lolThe 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. 🧐
Comment #50
senzaesclusiva commentedYou 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
Comment #51
jorgefernandes commentedWe 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.
Comment #52
senzaesclusiva commentedHi @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
Comment #54
veskimees commentedIt'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.
Comment #55
b0gucki3 commented#49 worked for me. Many thanks!
Comment #56
mkalkbrennerWe'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!Comment #57
mkalkbrennerHere's a patch that could be included in composer patches.
Comment #58
drupalfan2 commentedAdded 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).
Comment #59
amavi commentedHi :)
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]
Comment #60
2dareis2do commentedI 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)
Comment #62
ddavisboxleitner commentedI 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.
There may be a smarter way to handle this special case. For now, this code will prevent the bug from appearing.
Comment #64
amavi commentedI 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...
Comment #65
floown commentedHello,
I have randomly the same problem.
Will there be a backport to Drupal 10 latest?
Regards
Comment #66
liam morland@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.Comment #67
joris drupal commentedI just want to report that on D10 10.4.3
I have a had the issue with index.php appearing and solved that by updating the nginx config, to include a rewrite.
I could replicate the problem by clearing the cache and directly afterwards navigating to https://mydomainname/index.php
from then on all cached urls would include the index.php
But now I have a simular problem with
/core/install.php/ appearing,
I suppose I am going to include a rewrite for that one too.... I cant explain it
Comment #68
2dareis2do commentedI think this has been mentioned already but I don't see this issue after installing the redirect module.
Comment #69
floown commentedHello,
I don't know how it can be done, but I've noticed that I've solved this problem by using an external cron job, launched by my server, rather than using Drupal's internal cron.
Regards.
Comment #70
catchThe path module doesn't do anything with index.php so moving to base system.
Comment #71
simeReiterating what #20, #26, #27, #29 ... etc have said: #5 seems to be working for us after about a month in production.
Comment #72
trevorbradley commentedI have the advantage of this not being on a production system yet, so I can mess about with things a little more.
I transitioned our dev site from one server and URL to another. The new site has the index.php issue, the old one does not. I still have access to both unaffected and affected servers.
Installing the redirect module on the affected system solved the problem, but removing it caused the problem to return.
For me, the issue seems to only affect the admin_toolbar menu system. If I'm on /admin/content, all the content links seem fine, but the admin menu links (except for Back to Site) are prefixed by index.php.
Very interesting: I pulled the DB from the affected system to my local, and index.php's appeared in the links. But when I cleared the cache with drush cr on my local, the links returned to normal.
Clearing the cache on the affected site obviously does nothing.
Checking the Status reports of unaffected and affected site. Both running apache 2.4.62. No obvious differences in status page, no obvious differences in drush status page.
My thoughts after playing with this for an hour: If the issue can be "undone" by moving the DB to a new site and clearing the cache, it's suggestive that the site cache is somehow being polluted by some kind of local environment setting.
Comment #73
ressaThis is a long shot, but since the cache situation acts differently, could it be that some caches persist or are cleared, depending on environment? See #3540339: Rebuild all caches, including APCu, when clicking "Clear all caches".
UPDATE: No, I tried with the APCu cache clear method as well, and it made no difference.
Comment #74
trevorbradley commentedMore data. I tried installing this in a new AWS deploy with no database, and the index.php showed up immediately, without any database.
My previous statements about index.php showing up with the DB implies an issue that gets set up in the cache.
But this is definitely environment specific.
I might have access to one AWS ECS environment where this is happening always, and another AWS ECS where it is not, with the same codebase. Going to see if I can reproduce that this isn't working and gather data about the differences.
Comment #75
trevorbradley commentedInstalling the Redirect module doesn't work for me, because it sends my homepage into an infinite loop.
I want to solve this. I have an affected server, an unaffected server, and no care for modifying files in vendor and core to figure out what's the heck is going on.
I've looked at URL construction and dug all the way back to the root index.php and then back to vendor/symfony/http-request/Request.php.
The baseUrl returned from
$request = Request::createFromGlobals();
in the root index.php is polluted with /index.php on affected servers.
I tried digging down deep into createFromGlobals, and it looks like there's some weird shell game going on in vendor/symfony/http-request/Request.php where the baseUrl is being set.
Looking at the variables from the affected servers, it seems $server['REQUEST_URI'] is index.php on the affected server, and empty on an unaffected server.
I can (mostly) replicate the problem by adding:
$_SERVER['REQUEST_URI'] = '/index.php';
before
$request = Request::createFromGlobals();
(Though this does also seem to break the entire theming system)
My .htaccess files are the same on both servers.
This really feels like an apache not handing off the clearing of $_SERVER['REQUEST_URI'].
Looking at the answers above, I concur that some kind of REQUEST_URI issue. Solution #57 seems to work for me, I'm going to try it instead of the redirect module.
Comment #76
trevorbradley commentedOne last note. For some reason, a drush cr was insufficient to clear the index.php out of the cache, but clearing the cache using the UI worked. Would have thought that was a fluke but it's happened twice now.
+1 to #57. Seems to be working great.
Comment #77
fagoAlso running into this issue. Seems like #2753591: Fix mismatch of $base_url with Symfony request object could help solving this.
Comment #78
joris drupal commentedSee my comment #13, in my experience happens when the very first request after a cache clear contains /index.php, then it will stick.
That explain it not happening in the ui but with drush cr, somehow your cache clear primes with /index.php, or the underlying system, or a cron or something...
Comment #79
fagoI don't thank that Drupal caches the base-path, that's determined fresh from each request.
Based on what I've seen and read, I think what is happening is this:
1. cache clear - no pages cached
2. Frontpage is one of the first hits at /index.php - with some server configuration Drupal generates now wrong links which point to /index.php/
instead of /page
3. Users and bots are following wrong linkes to /index.php/
. Drupal wrongly generates the page with basePath /index.php
4. Wrongly generated caches end up in page cache.
Comment #81
fagoI've added a test-case demonstrating the issue, as I described it in #79. (branch 3050261-test-case-2 in issue fork)
Disclosure: I used AI to help creating this.
Comment #82
sparsh.sinhaI’m also running into this issue on a Drupal 10 site.
Bing has indexed a few URLs that include /index.php/ (for example: https://www.example.com/index.php/test-site). Everything works correctly in Google. This only happens for a few pages, not the entire site which makes me think Bing may have crawled those pages when /index.php was temporarily exposed somewhere (possibly through cached or sitemap URLs).
After enabling the “Enforce clean and canonical URLs” option in the Redirect module, those /index.php/... URLs now correctly redirect to the clean version (e.g., https://www.example.com/test-site). However, I’m not sure how or when Bing will remove the old /index.php URLs from its search results after these redirects are in place.
Comment #83
tolstoydotcomI had this same problem (D10.5.4) and manually applied the patch in #56. So far it seems to be working, I'll update this if there's a problem.
Comment #85
sleitner commentedThe tests are failing if unclean URLs are required. I don't think we can solve this problem without saying goodbye to unclean URLs in Drupal.
Comment #86
sleitner commentedDo we have statistics how many Drupal 10/11 sites are running without clean URLs (URLs starting with index.php)?