CodeIgniter Forums

Full Version: Different URI segments because subfolder?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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!
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?
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
Look in the CodeIgniter Users Guide - URI Class - segment
(07-13-2017, 03: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... :-)
It most likely does not know where to find HOMOLOGACAO in the path because it goes by the base_url
Did you set the bases_url in your config file to include your subfolder ?


Code:
$config['base_url']= 'http://xyz.hospedagemdesites.ws/HOMOLOGACAO/';
(07-14-2017, 04: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.
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...
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.
Pages: 1 2