000webhost and codeigniter
Asked Answered
R

1

7

Im trying to use codeigniter in a shared server at 000webhost. I uploaded the content of the pack and if I enter

http://groceriesapi.000webhostapp.com/API/index.php/welcome/

it does indeed work. But if I visit:

http://groceriesapi.000webhostapp.com/API/welcome/

you get a 404.

I read in the internet that one should solve this issue with .htaccess file. First off, I have two of them in my folder structure. This is how it looks like:

public_htm
    application
       plenty of things
       .htaccess
    other stuff
    .htaccess

I edit the outer .htacces, the one at public_html to look like this:

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

and now when visiting the simplified URL (http://groceriesapi.000webhostapp.com/API/welcome/) I get a 500 Internal server error!

Any clue ???

PS: I would not care about the index.php in the middle of the URL but whenever I get an error message the whole codeigniter blows up and I don't know what went wrong .. and that's a problem :(

Rutaceous answered 19/7, 2019 at 14:15 Comment(4)
Probably what you are looking for is this? https://mcmap.net/q/142071/-codeigniter-removing-index-php-from-urlWampumpeag
Dude.. I tried this 200 times from every single post in SO and did not work.. but your's did work. Only difference .. I did not restart apache since it is a shared server. How can I solve this question ? or should I close it or.. what ?Rutaceous
I will post an answer with that thread as a reference and you can accept it as an answerWampumpeag
Done, answer posted.Wampumpeag
W
3

Step:-1 Open the folder “application/config” and open the file “config.php“. find and replace the below code in config.php file.

//find the below code   
$config['index_page'] = "index.php" 
//replace with the below code
$config['index_page'] = ""

Step:-2 Go to your CodeIgniter folder and create .htaccess

Path:
Your_website_folder/
application/
assets/
system/
.htaccess <——— this file
index.php

Step:-3 Write below code in .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>

Step:-4 In some case the default setting for uri_protocol does not work properly. To solve this problem just open the file “application/config/config.php“, then find and replace the below code

//find the below code
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI" 

Thats all but in wamp server it does not work because rewrite_module by default disabled so we have need to enable it. for this do the following

  1. Left click WAMP icon
  2. Apache
  3. Apache Modules
  4. Left click rewrite_module

Original Documentation

Example Link

PS: This answer is a word to word copy from CodeIgniter removing index.php from url. Only posted here because the question had to be answered as a part of bounty

Wampumpeag answered 23/7, 2019 at 14:54 Comment(1)
Just add that I used it in a shared server so I did not reboot Apache after all, still worked like a charmRutaceous

© 2022 - 2024 — McMap. All rights reserved.