Search code examples
php.htaccesscodeigniterurl-rewritingshared-hosting

How to remove the root folder name from codeigniter application


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

https://webdomain.com/myproject/controller/function

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


Solution

  • 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.