Welcome Guest, Not a member yet? Register   Sign In
Problem with controllers in the URL

Hello, guys.

I'm facing a problem for which I can not understand the reason.

I don't have such a problem in my local environment (linux and windows), but the problem occurs when I put my site on hosting provider server.

My site is beauty-review.ru.

if you enter it - the controller by default is MAIN.
As you can see I echo there in the top:
echo $this->uri->rsegment(1).'/'.$this->uri->rsegment(2);
and I get /main/index/ by default.

the problem is when I click for the second tab - "reviews" (displayed as "Обзоры") (I have such a controller) - I still get loaded the main page (main/index), while in the URL there is /reviews displayed.

I asked the support of my hosting provider what can be the problem - the response is that on the server side everything is fine - probably the problem is in configuration of my site.

I'm using CI 1.7.1.

In my routing config I have:
$route['default_controller'] = HOME;
$route['scaffolding_trigger'] = "";

//readress all personal blogs to general ajax controller
$route['user/index/[^/]+/(ajax|img)(/.*)?'] = '/$1$2';
//readdress all blogs to index
$route['blogs/(.*/)page(:num)$'] = "blogs/index/$1page/$2";
$route['blogs(/.*)?$'] = "blogs/index$1";
//general reroutings
$route['(all)(/.*)page(:num)'] = HOME."/$1$2page/$3";
$route['(all)(/.*|$)'] = HOME."/$1$2";
$route['(page)/?(:num)'] = HOME."/$1/$2";
$route['(.*)/page(:num)'] = "$1/page/$2";
//if after the top is not topics, comments, blogs, people - then add topics
$route['top$|top/(?!topics|comments|blogs|people)(.*)'] = "top/topics/$1";

where HOME is a constant and equals 'main'.

What I have found is that when I change default controller to:
$route['default_controller'] = '';

and try to access e.g. http://beauty-review.ru/reviews/ I get an error:

An Error Was Encountered
Unable to determine what should be displayed. A default route has not been specified in the routing file.

while I'm refering not to the root of the site but to 'reviews' controller.

in my .htaccess I minified all conditions and now I have only:
RewriteCond $1 !^(index\.php|img|debug_images|images|robots\.txt|captcha|css|js|phpmyadmin|user_guide|stats|techpause\.html)
RewriteRule ^(.*)$ index.php/$1 [L]
so that /index.php/.. would be added.

Here are two screens that may help to understand what is the problem:

1. this is what happens on hosting server:


2. and this is the same site but locally on my machine - as you can see
everything is fine:


If anyone have faced similar problems or may assume what potentially may
cause such a behavior - please, help, because Im really frustrated because
of it.

Did You define the constant HOME with 'MAIN' ?

Frankly, this is too mind-blowing for me. Do You think You'll understand this next year when You reread it ?

I avoid routing and set .htaccess up only after everything works.

Your links are ok, probably the routing bugs. Guess You have to check them one by one to see where.

I do not believe You will ever have a stable, predictable behaviour with so many rules.

I'd recommend You to rethink Your URI structure, there are other possibilites, number 1 is keep it simple.

EDIT : take out Your .htaccess, change the config 'index_page' and see whether it works. If so, try the different flavours of the config 'uri_protocol'

Thanks for your response.

Quote:>Did You define the constant HOME with ‘MAIN’ ?
sure in config/constants.php I have:
//default blog
define('HOME', 'main');

Quote:>Frankly, this is too mind-blowing for me. Do You think You’ll understand this next year when You reread it ?

actually, I don't find them difficult. Most of them are regarding pageN/->page/N/ modification.

Quote:>I avoid routing and set .htaccess up only after everything works.
all these configs and routing are working fine at my machine. So there were no problems during development. The problems appeared when I tried to place it to server.

Quote:>EDIT : take out Your .htaccess, change the config ‘index_page’ and see whether it works. If so, try the different flavours of the config ‘uri_protocol’
I used another approach.
I totally erased everythig from public_html folder.
Then putted there Codeigniter 1.7.1. version as it is available for download.
The only change I did is changed base_url to:
$config['base_url'] = "http://beauty-review.ru/";

Then I created my 'test.php' controller with the following content:

class Test extends Controller {

    function index()
        echo 'We are on the test controller!';

/* End of file test.php */
/* Location: ./system/application/controllers/test.php */

Then I go to my browser and input main site path: http://beauty-review.ru/
I receive a standard Codeigniter welcome message.

But when I change URL to http://beauty-review.ru/test/ I expect my controller to be processed, but it is showing me:
Not Found

The requested URL /test was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.7a Phusion_Passenger/2.1.3 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/ Server at beauty-review.ru Port 80

So now I do beleive that the problem is not in codeigniter and it's routing settings - but somewhere else even before php interpretator is starting to process.

Support of web hoster is continuing saying that there are no problems on their side.

Could you advise anything in such a situation?

You did use the wrong URL

instead http://beauty-review.ru/test/

You need http://beauty-review.ru/index.php/test/

sure, my fault.

yes, when I put http://beauty-review.ru/index.php/test/
it is loaded correctly as "We are on the test controller!"

So everything is fine until this moment.

The next step I do - is add into .htaccess simple rule:
RewriteEngine on
RewriteCond $1 !^index\.php
RewriteRule ^(.*)$ index.php/$1 [L]

I expect that all urls should be redirected to index.php/...

then I enter http://beauty-review.ru/test/

it is now not showing 404 error, but I am displayed the welcome message instead, as if I am entering the default Welcome controller.
this mistake is similar to the error I have on my real site.

Any thoughts on this?

Try the different flavours of the config ‘uri_protocol’

tomcode, you saved my life.
thank you very much.

PATH_INFO, QUERY_STRING are giving the same result as AUTO.

But REQUEST_URI and ORIG_PATH_INFO are giving the needed result.

So the problem fix is found, but I still don't understand the way it processes and what these directives are doing actually. So there is something to search and read.

Anyway - thanks, because I have started thinking even about change of hosting company Smile)

You'll have that issue with a lot of hosters, it depends how the server is set up, which and how the $GLOBALS are filled.

Do not forget to set up Your error documents Wink


Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


by error documents you mean for example 404 page in CI?
or you mean error pages to be displayed when PHP-engine is down for example?

Because I have 404 customized page in CI.

I mean the error pages generated by the web server BEFORE CI is initialized.

Your hoster does not have them set up, at least not for 404 errors. Remember the exemple when You had deleted Your app (see my last quote).

Theme © iAndrew 2016 - Forum software by © MyBB