DavidAM Posted June 16, 2009 Share Posted June 16, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/162479-solved-session-hangs-with-mod_rewrite/ Share on other sites More sharing options...
DavidAM Posted July 26, 2009 Author Share Posted July 26, 2009 Well, if anybody is interested, I found a solution. I cleaned up my apache config file, removing all Virtual Host entries, and generally making it more like the standard config file. This had no impact. Then on a whim, I changed the order of the LoadModule commands from: LoadModule php4_module modules/libphp4.so LoadModule rewrite_module modules/mod_rewrite.so to: LoadModule rewrite_module modules/mod_rewrite.so LoadModule php4_module modules/libphp4.so This seems to resolve the problem. One caveat though. The rewritten pages did not display error messages. All my pages start with error_reporting(E_ALL);. Again, requesting the page with the standard url (trw.php?id=2) allowed the errors to show, but requesting the "clean" url (trw/2) did not. I looked through my php.ini and found display_errors = Off. I don't know why it displays errors without the rewrite, but once I changed it to On, it starting working. Quote Link to comment https://forums.phpfreaks.com/topic/162479-solved-session-hangs-with-mod_rewrite/#findComment-883356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.