Welcome Guest, Not a member yet? Register   Sign In
routes question

(This post was last modified: 01-11-2023, 02:49 PM by dgvirtual.)

This is only partially a Codeigniter question perhaps, but since I am working with CI, I will give it a shot.

My app's public files are placed on a subdirectory of a domain, say:

The server is an apache server.

And I need to make one controller accessible to the outside world in a way that the subdirectory through which the app is accessible would not be visible; let's say the controller is Dogfood.php and I need it's methods to be accessible via such link: 


So, if a user tries to access https://mydomain.com/dogfood/, he would be, under the hood, accessing https://mydomain.com/movies/dogfood/. But this should be hidden from the user.

I can write a rule in the public_html/ folder's .htaccess file that would work for regular files if the "dogfood" was a directory (without it's own .htaccess file), so trying to access https://mydomain.com/dogfood/image.png would load https://mydomain.com/movies/dogfood/image.png :

RewriteRule    "^dogfood/(.*)$"  "/movies/dogfood/$1" [PT]

But, if I try it on a CI4 installation in the movies folder and instead of files try to access the methods of dogfood controller, that same rule in combination with codeigniter's .htaccess file produces a redirect, revealing the address https://mydomain.com/movies/ to the user.

Is there any simple solution to this issue?

Here is the .htaccess file in the subdirectory movies/ where the public CI4 installation files are:

# Disable directory browsing
Options All -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase "/movies/"

# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php

# Disable server signature start
ServerSignature Off
# Disable server signature end

Donatas G.

(This post was last modified: 01-11-2023, 09:24 PM by luckmoshy.)

I am not sure if is this what you're looking for!!!!

  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteCond %{THE_REQUEST} /moviefolder/([^\s?]*) [NC]
  RewriteRule ^ %1 [L,NE,R=302]
  RewriteRule ^((?!moviefolder/).*)$ moviefolder/$1 [L,NC]
Codeigniter First, Codeigniter Then You!!


Not sure if this will help, but give it a look at.

Redirect Multiple Domains to Subfolders and Hide the subfolder from URL
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

(This post was last modified: 01-12-2023, 02:34 AM by dgvirtual.)

Thanks everyone for suggestions, but those do not seem to work. I guess I need a very coplex solution here, since there is an interplay of the server root .htaccess file rules, the subdirectory .htaccess file rules and then the configuration of the app itself (like the variable in .env app.baseUrl, which should be different depending on the controller the user tries to access...)

I guess I need to find an apache wizard to make it all work Smile

But maybe someone can suggest if it is possible to have different configuration option values of app.baseUrl depending on the route via which the app is accessed?


Donatas G.

Theme © iAndrew 2016 - Forum software by © MyBB