RewriteRule creating 500 Internal Server Error

You should try adding a forward slash to the front:

RewriteRule ^/directory/(.*)$ directory/index.php?id=$1

I've been caught out with that before.

Alternatively use the RewriteLog and RewriteLogLevel to debug, and look at the Apache error and access logs for further info:

RewriteLogLevel 3
RewriteLog ${APACHE_LOG_DIR}/rewrite.log

That will leave a log file in your apache log directory. In my case that is /var/log/apache


Your code is guaranteed to generate 500 internal server error because it is causing infinite looping. Reason is that your matching URI pattern is: ^directory/(.*)$

Which matches your URLs before and after rewrites. And once it reaches max allowed internal rewrite limit Apache throws 500 internal server error and bails out.

Change your code to this:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^directory/(.*)$ directory/index.php?id=$1 [L,QSA,NC]

Above code has an extra RewriteCond %{REQUEST_FILENAME} !-f that will make sure to disallow subsequent execution of RewriteRule after first time since /directory/index.php will be a valid file.


I have got the same issue and found that "rewrite" module is not yet enabled in my case. So I need to enable it and then restart apache server:

  • Enable "rewrite" module: sudo a2enmod rewrite
  • Then restart apache server: sudo service apache2 restart

Hope this will help anyone.