Welcome Guest, Not a member yet? Register   Sign In
codeigniter 3.1.9 with apache and php 7.2 - routing/redirect issues with sym link
#1

SCENERIO:
Recently I migrated CodeIgniter from 2.4 to 3.1.9 along with PHP from 5.2 to 7.2. Also, created a new httpd.conf file in apache. When I go to the site's URL, it loads the default page fine and I can browse to default or root
pages without any issues. There are multiple sub-domains that are mapped in routes.php to the main httpd root directory /var/www/html. These sub-domains have a symbolic link to /var/www/html, and within assets folder are
the customization files for each sub-domains.

Root HTTPD directory "/var/www/html" structure

application
assets
test1 -> /var/www/html    
test2 -> /var/www/html
index.php
system


URL is set as follows in config.php.

$config['base_url'] = 'https://example.com/';


Below is my entry in routes.php:

$route['default_controller'] = "home";
$route['404_override'] = '';

$route['home'] = "home";
$route['select-product'] = "home/select-product";
$route['test1/select-product'] = "home/select-product";
$route['test2/select-product'] = "home/select-product";


Below is httpd.conf file for the <Directory>


# Relax access to content within /var/www.
#
<Directory "/var/www">
    AllowOverride None
    Require all granted
</Directory>

# Further relax access to the default document root:
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
     AllowOverride All
    Require all granted
</Directory>


 

PROBLEM:
When I browse to https://example.com/ it loads everything correctly.
When I go to https://example.com/test1 ==> First page loads correctly. But when I press next, the second page defaults back to 'https://example.com/';. Somehow, it looses /test1 from the browser.

Not sure if this is caused by CodeIgniter URL routing issue or something to do with httpd.conf file of Apache. The same routes.php file was working fine on the old server.

The routing/pagination seems to have broken after I set $config['base_url'] = 'https://example.com/';. If left empty, it takes a while for the site to load, and when it does the forms and images are not loaded correctly.

I have spent lots of hours trying to figure out the problem. I am hoping someone genius out there will be able to show be in the right direction.


Thank you.
Reply
#2

Hi guys,
I am still trying to figure out this issue, and have run out of ideas.

I will be really thankful if someone could help me out with this one please.

Thank you.
Reply
#3

Do you have mod_rewrite enabled? Th eline in httpd.conf looks like
LoadModule rewrite_module modules/mod_rewrite.so

Note there is no hash sign at the beginning.
Reply
#4

You do not show a routing rule for "test1" on its own. That means that it would be resolved by either "application/controllers/test1/Home.php" or by "application/controllers/Home:test1()".

You don't need a route for "home". If "home" is the default controller, when www.example.com would be resolved as "application/controllers/Home:index()".
Reply
#5

Hi Cat,
Thank you so so much for y you reply. I really appreciate it.

What I've discovered might give us some clues in regards to what is happening... So, when I browse the web-page using the private IP it works fine. When it is loaded with public IP, the home page loads, but the URL address on the next page changes to "Private IP" and it fails to load the page. This behaviour is observed when $config['base_url'] = ''; is left empty and $config['uri_protocol'] = 'ANY OPTION WORKS';

I am having same issues while browsing through Public IP.

Hoping to hear from you soon.

Thank you.
Reply
#6

Do you have your web browser set to private browsing?

I have no problem on my setup.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

Hi InsiteFX,
Thank you for your response. Browser is not set to private mode.

I have been trying to figure out the root cause for quite some time now without success. Not sure why it is behaving this way...any other ideas please......??

I don't think I will be able to get it working without the help of this group forum community. Please provide your ideas or suggestions.

Thank you.
Reply
#8

(This post was last modified: 07-05-2018, 08:43 AM by jreklund.)

Quote:When I go to https://example.com/test1 ==> First page loads correctly. But when I press next, the second page defaults back to 'https://example.com/';. Somehow, it looses /test1 from the browser.

Are the second link also https://example.com/ or a subdomain?

As of 3.0 you need to write your $config['base_url'] like this for multiple domains:
https://www.codeigniter.com/user_guide/i...-not-empty
Reply
#9

(This post was last modified: 07-05-2018, 08:11 PM by BBT.)

(07-05-2018, 08:43 AM)jreklund Wrote:
Quote:When I go to https://example.com/test1 ==> First page loads correctly. But when I press next, the second page defaults back to 'https://example.com/';. Somehow, it looses /test1 from the browser.

Are the second link also https://example.com/ or a subdomain?

As of 3.0 you need to write your $config['base_url'] like this for multiple domains:
https://www.codeigniter.com/user_guide/i...-not-empty

Hi jreklund,
Thank you for your feedback. I think we are now closer to the problem, but still not working for me with the below code added to config.php.

$allowed_domains = array('example.com', 'example.com/test1');
$default_domain  = 'example.com';

if (in_array($_SERVER['HTTP_HOST'], $allowed_domains, TRUE))
{
        $domain = $_SERVER['HTTP_HOST'];
}
else
{
        $domain = $default_domain;
}

if ( ! empty($_SERVER['HTTPS']))
{
        $config['base_url'] = 'https://'.$domain;
}
else
{
        $config['base_url'] = 'http://'.$domain;
}


Second links to https://example.com/ are sub-domains, and the routing has worked fine in the older version of CodeIgniter.

Desirable outcome:
When I browse to https://example.com/test1, fill up the form and click continue, the next page should navigate to https://example.com/test1/select-product and utilise the below routes.php entry to handle this process

$route['test1/select-product'] = "home/SelectProduct";

What is happening now:

I can browse to https://example.com/test1 directly, and it presents the page with customised icons for test1 as expected, but when I click on "continue" the web page reverts back to default_url ==> https://example.com/ instead of https://example.com/test1/select-product.

Could you please advise what could be wrong?

Thank you soooooooooooo much in advance.
Reply
#10

(This post was last modified: 07-05-2018, 11:26 PM by jreklund. Edit Reason: Formatting )

Hi again, those aren't sub-domains. These are:
test1.example.com
test2.example.com
example.com
example.net

So in your case you really should only have:
$config['base_url'] = 'https://example.com';

Try changing the order of the route.php
PHP Code:
$route['test1/select-product'] = "home/select-product";
$route['test2/select-product'] = "home/select-product";
$route['select-product'] = "home/select-product"

If you view the source of the <form> you are submitting, what actual URL have you got?
<form src="https://example.com/test1">...

How do you redirect the user to /test1/select-product?

Activate the debug mode.
/application/config/config.php
$config['log_threshold'] = 4;

You should now get logs inside /application/logs/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB