Codeigniter 4 subdirectory controller not accessible on remote server - codeigniter-4

I just almost completed project in Codeigniter 4 and published it on hosting server. And now I am not able to access controller that is inside subdirectory.
For example:
http://localhost/admin/auth/ - this URL works fine.
And when I access it on hosting server:
http://x.someserver.com/admin/auth/
Then I am getting this error:
It's trying to load admin controller which doesn't exist. Here is how my controllers are structured:
Note: Root.php is my default controller.
I am not sure why this is happening. Or how can to resolve this.
Here what I have found online similar issues.
One states that it needs to be namespaced.

The screenshot of your filesystem shows your admin/ directory is all lower case. It should start with a capital A. From the docs:
Organizing Your Controllers into Sub-directories
If you are building a large application you might want to hierarchically organize or structure your controllers into sub-directories. CodeIgniter permits you to do this.
Simply create sub-directories under the main app/Controllers/ one and place your controller classes within them.
Important
Folder names MUST start with an uppercase letter and ONLY the first character can be uppercase.
If you would rather use lower case a, or if you simply want more transparent control of your routing, set up routes.

Related

Apache Map All Paths to Root Without Redirect

I want Apache to blindly give the root website directory the full URL without a concern for the path. Reason being I have an Angular app that handles routing and it's at the root directory.
I've tried stuff like this:
AliasMatch ^/(.+) /var/www/html/mywebsite.com
But it always results in an infinite loop.
Essentially, I just want to disable path-directory resolution.
EDIT: I should also clarify that I have multiple sites hosted on the same machine and still want that to function. I just don't want directory routing from within a single website.
I figured out how to accomplish what I want while also having the neat side effect of allowing me to still have assets that can be reached through directory navigation:
FallbackResource /
Will use the root directory without changing the URL when no such directory the path specifies exists.

Creating custom domain names for api

I have a web server using cpanel and I would like to use a custom domain on one folder for an api. So if I created a folder called api in the public_html folder then the path to that folder would be www.example.co.uk/api/(some php file). How could I change it so the folder would become a custom domain of api.example.co.uk/api/(some php file).
I have looked at a few options but don't really know the best way. I have tried to add a htaccsess file to the api folder and then create a rewrite rule to rewrite the www to api.
I also then looked at creating sub domains with the path to the api folder.
I have read that creating a A record on the server could work but I'm not quite sure how to do this. I know it can be done as most apis use some custom domain like facebooks graph api. (i.e https://graph.facebook.com/youtube/)
This will depend on if you have access to make DNS records for your root domain, example.co.uk. For example right now www. is a CNAME or A record (depends on how your web server is set up), that resolves to the address of your web server. If you made an identical record but named it api. (api. IN A ip-of-webserver), then api.example.co.uk would do the same thing that www.example.co.uk does. This is kind of pointless if they go to the same web server though, the /api/ part of the route makes it clear enough that the routes are for the api. What subdomains like facebook's are doing are pointing to a completely different application, and different web servers. For example, a company may have domains like mail.company.com, portal.company.com, sso.company.com, that all resolve to the address of different web servers for the different apps they have, but in this case it sounds like you are running one web server which is fine, you can have one web server be the api as well as serve the website.

How do you specify a single IIS handler mapping path that applies to all URIs under a single subdirectory?

How can I configure a single IIS handler mapping path to allow all traffic starting with /rest/*, regardless of the number of subdirectories/subpaths, to be forwarded to ColdFusion?
Background: We run Lucee 4.5 behind IIS 8 connected with BonCode on our production environment. We are trying to implement our first of many REST endpoints using the native REST functionality in Lucee. As a result, all of our REST URIs begin with /rest/ even though this is not configured anywhere as a physical or virtual directory. I am able to add individual handler mappings to IIS in order to successfully pass traffic to specific subdirectories to ColdFusion.
The following are all examples of REST URIs and the associated handler mapping path that I had to add in order to get them to work. I would like to add a single handler mapping to encompasses them all.
REST endpoint: /rest/logout
IIS handler mapping path: /rest/*
REST endpoint: /rest/service/callback
IIS handler mapping path: /rest/service/*
(the first mapping path of /rest/* would not work for "deeper" subdirectories).
Is there a way I can specify "all traffic beginning with /rest/* regardless of the number of subdirectories"? It seems like there has to be a way to accomplish this without needing to add new entries for every new subdirectory that comes along ... ? Many thanks.
Found it. Apparently my search-fu was weak last weak when I posted the original question. I went looking again and found a solution!
How to register HttpHandler for all subfolders in Asp.Net?
In a nutshell you define a object in the web.config that maps to the subdirectory/URI (in my case, /rest), and then add a single wildcard handler to that location which handles all requests under that URI.

Routing YII and CI

I have 2 (working well) applications providing APIs, old one is based on CodeIgniter 2.1 and new one on Yes It Is framework. I need to redirect some actions from old API to a new one. Routing should also provide filtering request methods such as GET, POST, PUT, DELETE etc.
Folder structure looks like this:
ci
yii
router
At first I wanted to redirect all traffic to router/index.php where depending on URI an appropriate app was loaded and started. It worked well with YII, but CI couldn't find it's controllers/models/actions.
Second idea was to use .htaccess, but I couldn't make CI, YII work neither. It's starting, but both of them cannot find it's controllers/models/actions. No errors are printed/logged into apache logs.
When those 2 apps are fired "normally" everything works properly.
I've been changing configuration paths (to absolute ones) and still nothing. I don't want to change those applications a lot, small fixes would be much better.
Also there should be no option to fire an app without checking URI with "routes".
Finally I stayed with PHP router as described in question post. It turn out that CodeIgniter couldn't find it's methods because predefined variable $_SERVER['SCRIPT_NAME'] contained a wrong path, since script was fired from another directory. I had it overridden in router file and everything seems to work properly now.

Password protect Laravel subfolder with htaccess

It seems I can't simply override Laravel's routing when trying to password protect a subfolder in views with htaccess. I put it and an .htpasswd file together in the folder that I wanted to create authentication for but with no effect.
The reason for this is I want to have "client's eyes only" folders for work in progress projects, e.g. "example.com/clients/my-client/". These folders will only contain static content.
I tried adding a folder tree in public but that doesn't seem to work either (I guess public content needs to be declared to avoid being routed?). I'd rather stick with having these client pages as views.
Ideas?
Running Laravel 4.2 on Apache.
Because of the way Laravel does routing, all URIs are actually virtual URIs, so you can't put .htaccess files within any directories, as they're not really there.
However, you can use Laravel's Auth system to protect your routes (either using basic auth or a more traditional login form system).
If you don't want to have to hook Laravel up to a database just to protect some directories there are a couple of solutions:
You can write your own Auth provider that will just lookup the details in a file or config array key. It's not super-difficult to do this, though it may seem a little over the top just for the purposes you have.
You could use the SQLite database driver, which stores the database in an easily-accessible file (in app/database/) so the database is at least kept alongside your code.

Resources