PHP Redirect not working in PHP5?

The_Mage18

[H]ard|Gawd
Joined
Jul 31, 2004
Messages
1,712
Well this is a strange little error to pop up. I upgraded from PHP4 to PHP5 via source compiling. Built the apache2 module, changed apache to use the new module, restarted apache and everything restarted and said it was playing happy.

Here's the twist: an older index.php, which contained nothing more than a redirect to another folder, doesn't work if the php5 module is loaded with apache but does work with php4. Yes, I kept the old module around should anything bizarre like this pop up. When I compiled php5, I let it use the default location of /etc for the php.ini file, same as php4, so that either module that is loaded would use the same settings.

Other than the bizarro redirect issue, everything else works fine. When I open the default link, apache spits back the normal error of Access Forbidden (I have apache set to deny file viewing so if there's no default or index file, it won't show anything but a 403). Now if I make an index.html and put in an html redirect, the link loads just fine. An index.html with the same php redirect script loads a blank page and goes nowhere.

The index.php redirect page:
Code:
<?php
header('Location: http://server/website/index.php');
exit;
?>

It almost seems like apache isn't recognizing index.php files as valid default pages BUT, if you type that link in the redirect into a browser manually, it opens with no errors. FYI the above link is a fictional link but shows the format of what the link really is.

Server stats:
Suse Enterprise 9.3
Apache2 (not sure of the exact version, too lazy to find out but definitly not the newest)
PHP 5.1.1
PHP 4.0.1
zend.ze1_compatibility_mode = On is set in php.ini
 
Any specific reason you're using PHP for the redirect and not, say .htaccess?
 
The_Mage18 said:
When I open the default link, apache spits back the normal error of Access Forbidden (I have apache set to deny file viewing so if there's no default or index file, it won't show anything but a 403). Now if I make an index.html and put in an html redirect, the link loads just fine.

If I just took this part of your message, and tried to fix the problem, I would say your Apache is misconfigured, or not configured to use index.php as a DirectoryIndex. It contradicts somewhat with parts of the rest of your message, but its at least something to check. There are 2 places it could be:

1) With Apache2, many of the config files, such as those for PHP, have their own conf file (/etc/httpd/conf.d/php.conf on my system). Check in there for DirectoryIndex.

2) If you can't find it in the above file, check in the httpd.conf, and search for DirectoryIndex.
 
SoRnMaN said:
If I just took this part of your message, and tried to fix the problem, I would say your Apache is misconfigured, or not configured to use index.php as a DirectoryIndex. It contradicts somewhat with parts of the rest of your message, but its at least something to check. There are 2 places it could be:

1) With Apache2, many of the config files, such as those for PHP, have their own conf file (/etc/httpd/conf.d/php.conf on my system). Check in there for DirectoryIndex.

2) If you can't find it in the above file, check in the httpd.conf, and search for DirectoryIndex.

That's just it, if I set apache to use the php4 module instead, it works but with php5 the index.php page with the redirect doesn't work. The actual index.php file in the folder I'm redirecting to works reguardless of what version of php is loaded with apache.

The only thing that I'm changing is in the file:
/etc/sysconfig/apache2
in the line:
APACHE_MODULES=access actions cgi php4 (etc.)
I'm changing php4 to php5, saving the file, stoping apache and restarting it via the script in /etc/rc.d. The libphp5.so module is located in the same folder as the php4 libphp4.so module.

If this is an apache problem, it doesn't make any logical sense that changing the module it's loading with no other changes would suddenly make it not recognize some index.php files and process others. I.E. http://server/index.php won't load but http://server/website1/index.php does. Also, as I stated in the first post, any php location redirects in any script in any file go unprocessessed. I'm beginning to think there's a bug in 5.1.1.

For the record, php uses php.ini which is in /etc unless you specify a location when you compile with with the --with-config-file-path=PATH option. Both php4 and php5 use the same php.ini file. I even tried using the "recommeneded" php.ini that came with 5 and I still have the same problem.
 
The_Mage18 said:
For the record, php uses php.ini which is in /etc unless you specify a location when you compile with with the --with-config-file-path=PATH option. Both php4 and php5 use the same php.ini file. I even tried using the "recommeneded" php.ini that came with 5 and I still have the same problem.

I wasn't talking about php's php.ini, I was talking about apache's config files, php.conf and httpd.conf.

So, the redirect works fine regardless of which php version you are using if you specify index.php in the url?
 
SoRnMaN said:
So, the redirect works fine regardless of which php version you are using if you specify index.php in the url?

Yes. I just tested it with php 5.1.0 and if you add index.php to the url, it works. The same with http://server/website1/index.php but if index.php isn't specified, you get the 403 error. Now with php4, you don't have to specify index.php
 
:eek: Good eyes SoRnMaN

Ok..... this is REALLY got me confused now. I just checked httpd.conf and found that index.php wasn't in the list. I added it and now the redirect does go to the correct folder now.

Now here's the real question: Why did it work with the php4 module and only now bomb with the php5 module? Sometimes I hate my life......
 
The_Mage18 said:
:eek: Good eyes SoRnMaN

Ok..... this is REALLY got me confused now. I just checked httpd.conf and found that index.php wasn't in the list. I added it and now the redirect does go to the correct folder now.

Now here's the real question: Why did it work with the php4 module and only now bomb with the php5 module? Sometimes I hate my life......

Not sure why you are experiencing this exact problem, it could be that there is something conflicting having both of them running, where one is including a file that the other isn't.

As for Apache 2, I believe by default it stores all config information for stuff like php, python, perl, ssl, etc in their own config files in conf.d. That is where my DirecoryIndex for index.php is, with DirectoryIndex index.html index.htm index.html.var being specified in the httpd.conf.
 
Back
Top