Skip to content

Instantly share code, notes, and snippets.

@kenjis
Last active March 31, 2024 08:08
Show Gist options
  • Save kenjis/a2b48a8b6f5bb7938ffe140f73ff24c0 to your computer and use it in GitHub Desktop.
Save kenjis/a2b48a8b6f5bb7938ffe140f73ff24c0 to your computer and use it in GitHub Desktop.

Note to "Deployment to Shared Hosting Services" Adding .htaccess

See https://codeigniter4.github.io/CodeIgniter4/installation/running.html#id4

Issue

When I navigate to http://localhost/ci4/users/, I am redirected to http://localhost/ci4/public/users.

How to Solve

.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

<FilesMatch "^\.">
    Require all denied
    Satisfy All
</FilesMatch>
--- a/public/.htaccess
+++ b/public/.htaccess
@@ -17,14 +17,14 @@ Options -Indexes
    # RewriteBase /
 
    # Redirect Trailing Slashes...
-   RewriteCond %{REQUEST_FILENAME} !-d
-   RewriteCond %{REQUEST_URI} (.+)/$
-   RewriteRule ^ %1 [L,R=301]
+   #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]
+   #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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment