Home » Php » php – How to remove the root folder name from codeigniter application

php – How to remove the root folder name from codeigniter application

Posted by: admin February 25, 2020 Leave a comment


I have my website hosted at https://www.webdomain.com/
The hosted website at the above domain IS NOT CODEIGNITER

On the server, at the location my_username/public_html/www/myproject, a Codeigniter application is hosted.

Meaning, to access a controller and its function in myproject application.

I use the following URL


As you may have already noticed, myproject is the root folder of the Codeigniter application

I’ve been trying to remove myproject from the URL, but with no luck.

I’ve gone through several questions on stack overflow, but as I figured it out, all of those questions refer to project directories, that are not necessarily application root directory. In my case, I want to remove the name of the root directory myproject from the URL.

This is my .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

How to&Answers:

Try this:

RewriteRule ^myproject/(.*)$ $1 [R]

This need to be in the root folder, I strongly recommend you go with @vivek_23 suggestion in the comment.


Have you try to set route in route.php file?

$route['controller/function'] = 'myproject/controller/function';


Try with .htaccess. I mainly used this on the localhost machine. This .htaccess file should be in the root of myproject folder. Here is the documentation for more information https://httpd.apache.org/docs/current/howto/htaccess.html

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /myproject/
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]


Hope this will help to out 🙂