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

(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:
https://mydomain.com/movies/

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: 

https://mydomain.com/dogfood/

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 :

Code:
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:

Code:
# 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>

<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
</IfModule>

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

Donatas G.
Reply


Messages In This Thread
routes question - by dgvirtual - 01-11-2023, 10:30 AM
RE: routes question - by luckmoshy - 01-11-2023, 09:23 PM
RE: routes question - by InsiteFX - 01-12-2023, 01:04 AM
RE: routes question - by dgvirtual - 01-12-2023, 02:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB