Mod_rewrite getting 500 server error, ubuntu server

Go To StackoverFlow.com

1

Hello i have been struggling alot today with my new home server. I have installed newest release of ubuntu server on it. Installed php, apache, mysql and everything seemed to work perfect.

I am trying to set up a website that worked perfectly with XAMPP on my local machine. I have been using this guide to set up mod_rewrite. http://www.solutionsamir.com/20110303140/Operating-Systems/Linux-Unix/How-to-enable-mod_rewrite-on-ubuntu-server-for-apache2.html

Here is my HTACCESS

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/?index.php$
RewriteRule . index.php

And here is my 000-default ` ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
    Options FollowSymLinks
    AllowOverride all
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride all
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride all
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

`

Its working somehow, but everytime i post a form, i get 500 internal server error. Any idea whats wrong?

Edit: This is what i get by activating logging.

    192.168.1.110 - - [04/Apr/2012:23:41:22 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (3) [perdir /var/www/serverpanel/] add path info postfix: /var/www/serverpanel/login -> /var/www/serverpanel/login/
192.168.1.110 - - [04/Apr/2012:23:41:22 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (3) [perdir /var/www/serverpanel/] strip per-dir prefix: /var/www/serverpanel/login/ -> login/
192.168.1.110 - - [04/Apr/2012:23:41:22 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (3) [perdir /var/www/serverpanel/] applying pattern '^(.+)/$' to uri 'login/'
192.168.1.110 - - [04/Apr/2012:23:41:22 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (2) [perdir /var/www/serverpanel/] rewrite 'login/' -> 'index.php'
192.168.1.110 - - [04/Apr/2012:23:41:22 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (3) [perdir /var/www/serverpanel/] add per-dir prefix: index.php -> /var/www/serverpanel/index.php
192.168.1.110 - - [04/Apr/2012:23:41:22 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (2) [perdir /var/www/serverpanel/] strip document_root prefix: /var/www/serverpanel/index.php -> /serverpanel/index.php
192.168.1.110 - - [04/Apr/2012:23:41:22 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (1) [perdir /var/www/serverpanel/] internal redirect with /serverpanel/index.php [INTERNAL REDIRECT]
192.168.1.110 - - [04/Apr/2012:23:41:22 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f5289230208/initial/redir#1] (3) [perdir /var/www/serverpanel/] strip per-dir prefix: /var/www/serverpanel/index.php -> index.php
192.168.1.110 - - [04/Apr/2012:23:41:22 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f5289230208/initial/redir#1] (3) [perdir /var/www/serverpanel/] applying pattern '^(.+)/$' to uri 'index.php'
192.168.1.110 - - [04/Apr/2012:23:41:22 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f5289230208/initial/redir#1] (1) [perdir /var/www/serverpanel/] pass through /var/www/serverpanel/index.php
192.168.1.110 - - [04/Apr/2012:23:41:52 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (3) [perdir /var/www/serverpanel/] add path info postfix: /var/www/serverpanel/login -> /var/www/serverpanel/login/
192.168.1.110 - - [04/Apr/2012:23:41:52 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (3) [perdir /var/www/serverpanel/] strip per-dir prefix: /var/www/serverpanel/login/ -> login/
192.168.1.110 - - [04/Apr/2012:23:41:52 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (3) [perdir /var/www/serverpanel/] applying pattern '^(.+)/$' to uri 'login/'
192.168.1.110 - - [04/Apr/2012:23:41:52 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (2) [perdir /var/www/serverpanel/] rewrite 'login/' -> 'index.php'
192.168.1.110 - - [04/Apr/2012:23:41:52 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (3) [perdir /var/www/serverpanel/] add per-dir prefix: index.php -> /var/www/serverpanel/index.php
192.168.1.110 - - [04/Apr/2012:23:41:52 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (2) [perdir /var/www/serverpanel/] strip document_root prefix: /var/www/serverpanel/index.php -> /serverpanel/index.php
192.168.1.110 - - [04/Apr/2012:23:41:52 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f528923b0a0/initial] (1) [perdir /var/www/serverpanel/] internal redirect with /serverpanel/index.php [INTERNAL REDIRECT]
192.168.1.110 - - [04/Apr/2012:23:41:52 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f52892304b8/initial/redir#1] (3) [perdir /var/www/serverpanel/] strip per-dir prefix: /var/www/serverpanel/index.php -> index.php
192.168.1.110 - - [04/Apr/2012:23:41:52 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f52892304b8/initial/redir#1] (3) [perdir /var/www/serverpanel/] applying pattern '^(.+)/$' to uri 'index.php'
192.168.1.110 - - [04/Apr/2012:23:41:52 +0200] [192.168.1.233/sid#7f52893ad1d8][rid#7f52892304b8/initial/redir#1] (1) [perdir /var/www/serverpanel/] pass through /var/www/serverpanel/index.php
2012-04-04 19:42
by NikolajSvendsen
Have you tried putting the two lines RewriteLog "rewrite.log" and RewriteLogLevel 3 in your 000-default? You may find their output helpful - Mike 2012-04-04 20:25
Tried it and added log abow - NikolajSvendsen 2012-04-04 21:46
Interesting - this suggests the 500 error is coming from the PHP script (and not from the apache config). I should note I am assuming you've checked ${APACHELOGDIR}/error.log and found nothing helpful. If PHP is causing the problem, you may need to enable error logging at the top of the PHP file - Mike 2012-04-05 05:56
Here's my theory: your browser is being redirected from serverpanel/login to serverpanel/login/ by moddir *before* modrewrite is invoked, and the browser is discarding the POST data. This causes the index.php file to die unhappily. You can use wget -d to check for any redirects (or curl -v ) - Mike 2012-04-05 05:58


1

Nice question, with logs. It deserves some attention ;)

As I can see it, you're trying to connect to your local URL login/.

Going through your rewrite rules, at the end, it's

/var/www/serverpanel/index.php -> /serverpanel/index.php

to it's redirected to another URL (not using the actual Php) which is /serverpanel/index.php.

So it tries to apply once again the rules, but with /serverpanel/index.php.

As you can guess, it will be rewritten to go to index.php, thus doing an infinite loop.

Take a close look at your log:

(1) [perdir /var/www/serverpanel/] internal redirect with /serverpanel/index.php [INTERNAL REDIRECT]

This may be the key to your solution: perdir /var/www/serverpanel/

2 questions:

  • Is there any .htaccess file here?
  • If there isn't any .htaccess, try to check all your Apache conf files, looking for a <Directory "xxx"> directive that concerns /var/www/serverpanel/, and you may find where the problem is.

Hope this helps

2012-04-05 07:26
by Olivier Pons
Ads