1

I am trying to get routing working in my SLIM PHP app. I need to create a .htaccess file in the same directory as my index.php like so :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

So I have my index.php in /var/www/html/example.co/public_html/API and also in that same folder is the .htaccess file mentioned above.

I have configured my virtual hosts in example.co.conf like so:

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin webmaster@example.co
  ServerName  www.example.co
  ServerAlias example.co

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /var/www/html/example.co/public_html
  # Log file locations
  LogLevel warn
  ErrorLog  /var/www/html/example.co/logs/error.log
  CustomLog /var/www/html/example.co/logs/access.log combined
  <Directory "/var/www/html/example.co/public_html">

        AllowOverride All

  </Directory>
</VirtualHost>

Now if I try to access any routes in my PHP app, even ones that worked before I get the error message:

<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>

I know this is a problem because of my .htaccess file because if I remove it the root link will work, i.e. www.example.co/API/. Any ideas what I am doing wrong with these files here? I am tearing my hair out over it. I have googled around and tried numerous combinations of different things in the .htaccess file but not had any luck. If someone could point me in the right direction I would massively appreciate it. thanks!

(Running a LAMP server on Linode)

KexAri
  • 3,867
  • 6
  • 40
  • 80
  • Peek into the `error.log` for a more concrete problem hint. – mario Jul 28 '15 at 12:30
  • where is that located? The php error log? – KexAri Jul 28 '15 at 12:31
  • `ErrorLog /var/www/html/example.co/logs/error.log` according to your config excerpt. – mario Jul 28 '15 at 12:33
  • Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration – KexAri Jul 28 '15 at 12:34
  • Did you check whether mod_rewrite is installed and enabled in the Apache conf? – tillz Jul 28 '15 at 12:35
  • WORKING!! It wasn't enabled. Had no idea it wasn't enabled by default. Ran sudo a2enmod rewrite and that fixed the problem instantly. Thank you so much! I will remember that trick for checking the error log in the future. I'm a newbie with this server stuff. thanks – KexAri Jul 28 '15 at 12:40

0 Answers0