-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: apache mod_userdir causes weird URL segment duplication #4471
Comments
I continued to investigate this by probing the Request object at the top of the Routes.php config. I discovered that the However, adjusting the path this way is doing something else, since instead I get I am going to try move the path edit into a 'before' filter to see if I can head off this exception. |
... setting the IncomingRequest path to |
I have found a workaround: If I prefix every route definition with the mod_userdir and install directory segments, then they will match properly and route to the controller. I still still think there is a bug somewhere here with respect to mod_userdir and mod_rewrite, but I'm at the limit of what I can reverse-engineer about how CI handles the path portion of the Request. I do hope this ticket gets looked at for a proper config or mod_rewrite-based patch. |
Thanks for the report. I’ve never used mod_userdir but a cursory glance at it makes me think it should not affect CI4 of your Apache Config and .htaccess are configured accordingly. My first guess on the “doubling” is that your baseUrl is not set correctly relative to the Apache directives. Try adjusting that in Config\App and if you are still having problems see if you can recreate the issue in a barebones AppStarter repo so it is easy to reproduce. |
Thanks for this @MGatner! I have verified my baseUrl many times and in many ways. I'm currently using the .env, but I've tried different values in \Config\App.php too. If there was something wrong with that config item, why would pre-pending my routes fix it? This seems like a pattern-matching issue in the comparison of the request with the baseUrl variable. Are we sure the regex that parses that string is accepting the tilde (~) as intended? The installation being assessed here is a brand new barebones AppStarter clone. It's why I posted the forum thread in "Installation and Config" rather than general Support. Any other ideas? |
My hunch is the issue resides in a layer before the PHP of the framework (like .htaccess) - but I will need to read more on mod_userdir before I can be of any real help in that area. To be continued once I am back on desktop... |
@MGatner Here is a scrubbed paste of the trace6 log I generated: https://pastebin.com/ZUnnv1C8 This shows everything apache does for mod_rewrite from the start of the request to the final serve of
Here is
My pretty standard
|
I have tried to install a CI4 application that uses your directory structure and was also not able to call the Controller from a public sub-directory? Here is a rough online demo called from the public directory with all the ~userdirs above the root. https://this-is-a-test-to-see-if-it-works.tk/~evan @evansharp, |
I can't speak much to the Apache layer of things but let's figure out what is reaching CodeIgniter to make sure everything coming "in" is correct. Can you interrupt the boot process (try app/Config/Boot/ with a |
@MGatner, Please note that the online demo appears to be working correctly. The problem is not being able to call CI4 from a public/evansharp sub-directory. @evansharp had the same problem with not being able to call an app/Controller/C_controllername.php which seems more than a coincidence that we both failed to call the necessary controller. I could zip the app folder if you want? |
Cracked it :) Modified app/Config/Paths.php
This should now work with mod_userdir(...); |
Please accept my apologies because although changing the app/Config/Paths.php should have been a solution. Further investigation discovered that setting $viewDirectory has absolutely no effect? It appears as though the app/Config/Views/ directory is used regardless? Sorry :( VIEWPATH is also not defined anywhere unlike CI3? File: app/Config/Paths.php
` |
https://forum.codeigniter.com/thread-78934.html I modified the $viewPath and added "Views" 👍 Also added this KLUDGE:
} Just noticed that an incorrect URL fails :) |
The KLUDGE was bothering me so I decided to investigate and discovered the following changes removed the need for the KLUDGE: file: .app/Conftollers/C_Others.php namespace App\Controllers; // ============================= // ============================= // ============================= if( empty($other) ) : elseif( in_array($other, $this->data['pages']) ) : else: # DOES NOT EXIST
endif; return view('v_evansharp', $this->data); }/// |
Impressive detective work @John-Betong! I find it hard to follow in comments, will you PR the patch? Ultimately does correcting this viewPath hardcoding allow the router to follow mod_userdir rewrites properly? |
Bump? @John-Betong @MGatner ? |
[quote] [quote] Please note that CI_VERSION 4.1.1 is used and PHP 8.0.5. Perhaps @MGatner has different thoughts? |
When you grab a new
Additionally remember you can use namespaces to access views so you can define a namespace that points to where you want your views to hang out, and then call them with the namespaced version of the view name. |
Forgive me @John-Betong and @MGatner, but we lost the plot around
This directed the investigation towards the viewpath, when the issue remains having the router locate a controller and method first. Take a look at my student's project: https://code.coastmountainacademy.ca/~kaimartin/hiperplanner/
We've hit the speedbump again though when the registration form gets submitted and tries to access You both know the boot better than I do, are there other suggestions than a pathing issue? |
I think I've got it, but it's a bummer: Apache mod_userdir follows a configuration directive in I now realize that simply placing a whole CI install ( Either mod_userdir must be configured to go deeper and serve Neither option is very clean since not every user of a shared host will be using it for CI, nor want to have the CI install in their home/. I am curious if anyone has an idea for redirecting apache from the install route into ./public in such a way that the subsequent url rewrites are not negatively affected; I think this will be the only way for a clean and universal support for mod_userdir. |
There are lots of threads on the forums about serving and securing root-directory index files, since it is a frequent issue with shared hosting. Apache directives have plenty of conditionals - could you not say "if exists ~/html_public/public, otherwise ~/public"? |
Yes, this is possible, but requires a nuanced server configuration. The third 'additional example' on the main docs page demonstrates a directive for multiple failover targets per user. This seems like useful info for the userguide; I'm going to draft an addition to the 'Running your app/Hosting with Apache' section. Not that we want to get into documenting Apache and Ngix, but explaining this logic could save some pain. I'm going to close this issue since enfin it is clearly not a CI bug. |
Resolution of issue codeigniter4#4471
Describe the bug
When using apache's mod_userdir to enable each server user to have a public site, CI's request class chokes on either the url rewriting or the tilde(~) in the url, making all controllers unreachable.
When the url string is echoed as a breakpoint at the top of the Config\Routes.php (with
echo (string)$request->uri;
), the userdir segment and install directory are both repeated, causing the router to always interpret the wrong segments of the URL.i.e. http://domain.com/~username/subdir/ becomes http://domain.com/~username/subdir/~username/subdir/ in the Request.
CI is bootstrapping fine and all system paths are resolving. Requesting the baseUrl though, that should be the default controller (splash screen), returns the CI 404 page citing a controller not found "\App\Controllers\ ~username::subdir".
My attempt to get support in the forums first is here. I can pastebin the rewrite log if it could be useful.
CodeIgniter 4 version
Whatever version is the dependancy for version 4.1.1 of the starter app on Packagist. Looks like 4.1.1-dev?
Affected module(s)
Probably HTTP/Request but might be Router?
Expected behavior, and steps to reproduce if appropriate
I expect the default controller to be served when requesting the baseUrl.
Reproduce on a system running mod_userdir and put CI in a subdirectory of the user's ~/public_html.
I have tried
RewriteBase
directive inpublic/.htaccess
to/~userdir/subdir/
; the issue does not seem to be with Apache's rewriting..env
andConfig\App
to include the segmentsdd( $request->uri )
is a bit baffling. CI seems to have the base url, but finds the last two as additional segments anyway.Context
The text was updated successfully, but these errors were encountered: