I've been searching for the solution to this, but can't find any similar problems. I am developing a website using a Linux box at the house. Running Debian 2.6.18-6-486, Apache 2.0.55, PHP 4.4.1. I have worked with PHP Sessions many times and had no problems. For this site, I wanted to use "clean" urls; so I started looking at mod_rewrite. I have it working, but when I combine the two, the server hangs.
.htaccess file (in document root)
RewriteEngine on
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(trw)/([^/]*)/?$ $1.php?id=$2 [L]
trw.php (also in document root)
<?php
/*
Testing mod_rewrite with Sessions
*/
error_reporting(E_ALL);
ob_implicit_flush(true);
//echo 'Start ... ';
session_start();
echo ' ... started!<BR>';
$_SESSION['ID'] = $_GET['id'];
?>
<HTML><HEAD></HEAD><BODY>
<H1>Testing mod_rewrite with Sessions</H1><BR>
<PRE>
<?php
echo 'GET: '; print_r($_GET);
echo 'SESSION: '; print_r($_SESSION);
//session_close_write();
?>
</PRE></BODY>
I can request (and receive) this file all day using a standard query string: trw.php?id=2 using any value for the '2'.
I can request (and receive) this file once using the "clean" url: trw/2 (again any value for '2').
After getting the page from this "clean url" request, all subsequent requests to the server just hang. The browser never receives anything.
If the subsequent request involves a rewrite, the entries appear in the rewrite.log (same entries as for the successful request). In any case, there are no entries in the access_log or error_log for this hung request. The only way to get the server back is to restart using apachectl. I am seeing this behavior in Firefox and IE. It has to be a problem on the server side.
Since the problem started I narrowed it down to the session_start function. As I said, sessions work fine without the rewrite; and the page works fine if a query-string is used (thus no rewrite). It is only the combination that seems to be causing the problem.
Has anybody ever seen this before, and more importantly, has anyone ever resolved this before?