CodeIgniter Forums
Different URI segments because subfolder? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: Different URI segments because subfolder? (/showthread.php?tid=68467)

Pages: 1 2


Different URI segments because subfolder? - fmertins - 07-13-2017

Hi, I'm using CI 3.0.6 with PHP 7.0.x and my URL is:

Code:
http://xyz.hospedagemdesites.ws/homologacao/index.php

The "/homologacao" is a subfolder. When doing this:

PHP Code:
$this->uri->segment(1

I get "homologacao", is that right? Because, it came *before* the front controller index.php...

And on my dev environment, same CI and PHP but at URL:

Code:
http://localhost/xyz/public_html/index.php

When running the same $this->uri->segment(1) I get an empty string, why...?  Confused
Thank you!


RE: $this->uri->segment(1) with subfolder - fmertins - 07-13-2017

I'm sorry, but I have been trying to find the bug and googling and comparing versions both of CI code and my code for ~3 hours and I have no idea whats going on :-( Very stuck :-(

I'm afraid all the examples of URI Segments have the index.php FC right at the domain root, not even one like "http://example.com/MYSUBFOLDER/index.php/news/local/metro/crime_is_up". In this case, I'm wondering how many segments do we have, 4 or 5? Or another approach: does the subfolders before index.php are counted as segments?


RE: $this->uri->segment(1) with subfolder - fmertins - 07-13-2017

OK I have a better comparison now.

It's the same site, but with two environments: production and testing. I just separate the testing environment cloning the application and system folders, the front controller index.php and other files likes css, js, user and static files, etc.

At the very top of the config/routes.php I put:

PHP Code:
var_dump($this->uri->segments$this->uri->segment(1), $this->uri->total_segments());exit; 

The production (normal) URL works great:
Code:
http://xyz.hospedagemdesites.ws/index.php/energia/nobreak

Code:
Output:
array(2) {
 [1]=>
 string(7) "energia"
 [2]=>
 string(7) "nobreak"
}
string(7) "energia"
int(2)

The testing URL, and now things get weird:
Code:
http://xyz.hospedagemdesites.ws/HOMOLOGACAO/index.php/energia/nobreak

Code:
Output:
array(4) {
 [1]=>
 string(11) "HOMOLOGACAO"
 [2]=>
 string(9) "index.php"
 [3]=>
 string(7) "energia"
 [4]=>
 string(7) "nobreak"
}
string(11) "HOMOLOGACAO"
int(4)

I'm getting different segments just because the index.php is inside a subfolder, is that right? Even more, the index.php itself turns out as a segment Confused


RE: $this->uri->segment(1) with subfolder - InsiteFX - 07-13-2017

Look in the CodeIgniter Users Guide - URI Class - segment


RE: $this->uri->segment(1) with subfolder - fmertins - 07-13-2017

(07-13-2017, 02:34 PM)InsiteFX Wrote: Look in the CodeIgniter Users Guide - URI Class - segment

Hi, thank you, but I already did this, it was one of my first readings... :-)


RE: Different URI segments because subfolder? - InsiteFX - 07-14-2017

It most likely does not know where to find HOMOLOGACAO in the path because it goes by the base_url


RE: Different URI segments because subfolder? - salain - 07-14-2017

Did you set the bases_url in your config file to include your subfolder ?


Code:
$config['base_url']= 'http://xyz.hospedagemdesites.ws/HOMOLOGACAO/';



RE: Different URI segments because subfolder? - fmertins - 07-14-2017

(07-14-2017, 03:53 AM)salain Wrote: Did you set the bases_url in your config file to include your subfolder ?


Code:
$config['base_url']= 'http://xyz.hospedagemdesites.ws/HOMOLOGACAO/';

Good morning, yes, I believe my base_url is correct, specially because I'm doing all the configs the same way I always did.

I added $this->config->config['base_url'] in var_dump() at very top of routes.php and got:

Code:
string(52) "http://xyz.hospedagemdesites.ws/HOMOLOGACAO/"

* * *

For today, I'm gonna create another subfolder, like MYSUBFOLDER along/sibling with the HOMOLOGACAO subfolder, then upload and configure a 100% fresh CI instalation, same version 3.0.6 with a single test controller to see what happens.

I'm still apreciate any help or suggestions, thank you.


RE: Different URI segments because subfolder? - fmertins - 07-14-2017

And the sentence of the day goes to...

Quote:The default setting of 'AUTO' works for most servers.

Well, it seems not to this server...  Angry  Tongue  Confused

Now it works, I had to change in config/config.php:

PHP Code:
$config['uri_protocol'] = 'QUERY_STRING'

Instead of "AUTO", which by the way always worked for me since kinda... 2007

Well, after ~5 hours trying to guess... I'm gonna compare some $_SERVER variables...


RE: Different URI segments because subfolder? - fmertins - 07-14-2017

Hi there, I'm sorry to inform that in fact didn't work, because only some URLs were OK, not all. Something about when I get only the root URL (only index.php) versus when I get a URL with segments.

I gave up after more a couple of hours trying to understand and make it work, I played with the other options in URI detecting but unfortunately none worked 100% ok.

I gave up using index.php inside a subfolder and gonna try with a subdomain.