Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have these rewrite rules in my site configuration:

RewriteEngine on
RewriteRule ^app.php - [L]
RewriteRule ^(.*)$ app.php$0 [L]

The goal is that all requests should be appended to the front controller "app.php". The last line of the rules is causing my server to respond with "400: Bad Request" no matter what path I try, even an empty path. I have enabled the rewrite log and attempted two paths: "/" and "/login". This is what the log says:

(2) init rewrite engine with requested uri /
(3) applying pattern '^app.php' to uri '/'
(3) applying pattern '^(.*)$' to uri '/'
(2) rewrite '/' -> 'app.php/'
(2) local path result: app.php/
(2) init rewrite engine with requested uri /login
(3) applying pattern '^app.php' to uri '/login'
(3) applying pattern '^(.*)$' to uri '/login'
(2) rewrite '/login' -> 'app.php/login'
(2) local path result: app.php/login

According to the logs it should succeed. If I remove the last line of the rewrite rules and visit the URL "app.php/login" then it works as expected.

Does anybody have any idea why this isn't working?

Note: There are no errors in the error logs.
Note: The resulting paths ("app.php/", "app.php/login") work perfectly when the last rewrite rule is removed.

share|improve this question
What is in your apache error log? Does using the URI app.php/login work if you don't have rewriting enabled? – Jenny D May 29 '13 at 8:39
@JennyD: I forgot to specify about the error logs, but I clearly state that the paths work perfectly when I remove the rewrite rule. Updated question. – Hubro May 29 '13 at 8:43
Sorry, missed that. Thanks for the correction! – Jenny D May 29 '13 at 8:44
up vote 3 down vote accepted

I figured it out. For some reason I had to append a "/" to the rewrite path:

RewriteRule ^(.*)$ /app.php$0 [L]

Otherwise, apparently, any path would rewrite to:


I have another server with the same Apache version where this did not occur so I'm still confused, but at least it works.

share|improve this answer
On the other server, do you by any chance have a RewriteBase directive? Or is one of them having the rewrite in httpd.conf and the other in a .htaccess file? See for an explanation. – Jenny D May 29 '13 at 9:17
@JennyD: Yes, you are absolutely correct in both your questions. My other server has the rewrite rules in a htaccess file and also uses RewriteBase /. That explains it then? – Hubro May 29 '13 at 9:26
Yep - RewriteBase / means that the / is automagically inserted at the start of the rewrite. – Jenny D May 29 '13 at 9:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.