Welcome Guest, Not a member yet? Register   Sign In
CI 2.1 in subdirectory not working
#1

[eluser]Unknown[/eluser]
Hello

I am starting getting crazy.

I have a project with a simple default controller (mycontr) that has a public function (myfunc), in addition to the index function.

If this project is in a root directory (e.g. http://localhost/myproject), everything works fine.
- http://localhost/myproject executes the index function of mycrontr
- http://localhost/myproject/mycontr/myfunc executes the myfunc function of mycontr.

Now, if I put this project in a subfolder (like http://localhost/sub1/sub2/myproject)
- http://localhost/sub1/sub2/myproject executes the index function of mycrontr, which is OK
- BUT http://localhost/myproject/sub1/sub2/mycontr/myfunc gives a 404 (generated by CI)

AND if I change the default controller in route.php to "mycontr/myfunc" then
- http://localhost/sub1/sub2/myproject executes the myfunc function of mycrontr -> which is OK as well

So I assume, my route and htaccess are correctly setup.

WHY do I have a 404 when executing a function of my controller, if the CI installation is setup in a subdirectory ???

Thanks for enlightning me before I become completely mad.
#2

[eluser]TWP Marketing[/eluser]
[quote author="opolette" date="1349904629"]Hello

I am starting getting crazy.

I have a project with a simple default controller (mycontr) that has a public function (myfunc), in addition to the index function.

If this project is in a root directory (e.g. http://localhost/myproject), everything works fine.
- http://localhost/myproject executes the index function of mycrontr
- http://localhost/myproject/mycontr/myfunc executes the myfunc function of mycontr.

Now, if I put this project in a subfolder (like http://localhost/sub1/sub2/myproject)
- http://localhost/sub1/sub2/myproject executes the index function of mycrontr, which is OK
- BUT http://localhost/myproject/sub1/sub2/mycontr/myfunc gives a 404 (generated by CI)

AND if I change the default controller in route.php to "mycontr/myfunc" then
- http://localhost/sub1/sub2/myproject executes the myfunc function of mycrontr -> which is OK as well

So I assume, my route and htaccess are correctly setup.

WHY do I have a 404 when executing a function of my controller, if the CI installation is setup in a subdirectory ???

Thanks for enlightning me before I become completely mad.
[/quote]
CI assumes the sequence of URL segments is http://localhost/myproject/controller/method[/param1][/param2]...
where the folder 'myproject' is mapped to the server document root. You can either change the document root in apache config (assuming you're using apache) or use routing to dynamically change how apache serves your URL to CI
#3

[eluser]alexwenzel[/eluser]
[quote author="opolette" date="1349904629"]
- http://localhost/sub1/sub2/myproject executes the index function of mycrontr, which is OK
- BUT http://localhost/myproject/sub1/sub2/mycontr/myfunc gives a 404 (generated by CI)

WHY do I have a 404 when executing a function of my controller, if the CI installation is setup in a subdirectory ???
[/quote]

'http://localhost/sub1/sub2/myproject/mycontroller/myfunction'

Should work!

Why would you except

'http://localhost/myproject/sub1/sub2/mycontr/myfunc'

should work, when you dont have stored your project in

'http://localhost/myproject/sub1/sub2/' but in 'http://localhost/sub1/sub2/myproject/'

?
#4

[eluser]skunkbad[/eluser]
You should look in config/config and let us know what your base_url is. If you're working in a sub-directory, your base_url will need to be set:

Code:
$config['base_url'] = 'http://localhost/myproject/';
#5

[eluser]PhilTem[/eluser]
You're using mod_rewrite, I guess? Is your RewriteBase set up properly? It should actually result in a server 404 but can also cause a CI-404 since the wrong arguments may be passed to index.php Wink
#6

[eluser]Unknown[/eluser]
Thanks everybody with the impressively fast responses!

It turned out that there was a simple mistake in my .htaccess (wrong uppercase in the RewriteBase path)!

Thank you all and let's code again!
:-)




Theme © iAndrew 2016 - Forum software by © MyBB