Apache2 server with php not finding sub-directories

I am trying to deploy a PHP app to my DigitalOcean server, running Ubuntu 14.04 with apache2 and php5

First let me mention that the application works perfectly on localhost using the built-in php-server

I am able to hit my index.php no problem by visiting "site.com/", but it gives me 404 on every other php file. I get 404 too when going directly to site.com/index.php My application uses a simple PHP-router to redirect to my controller which handles the views.

The apache server is set to point to /var/www/my_site/public

This is the file structure: File structure

This is my index.php:

<?php
use App\Core\Autoloader;
use App\Core\Container;
use App\Core\Router;
/*************
*   CONFIG   *
*************/
error_reporting(-1);
// dev only
ini_set('display_errors', 1);
define('SCRIPT_DEBUG', true);
define('VIEW_DIR', realpath(__DIR__ . '/../views'));
define('CONFIG_DIR', realpath(__DIR__ . '/../config/'));
/***********
*   INIT   *
***********/
session_start();
require __DIR__ . '/../App/Core/Autoloader.php';
require CONFIG_DIR . '/db.php';
$dbh = new PDO('mysql:host=127.0.0.1;dbname=' . $db_name, $db_user, $db_pass);
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$loader = new Autoloader();
$loader->addNamespace('App', __DIR__ . '/../App');
$loader->register();
$container = new Container();
$container->bindArguments('App\\Model\\User',   ['dbh' => $dbh]);
$container->bindArguments('App\\Model\\Image',  ['dbh' => $dbh]);
/**************
*   ROUTING   *
**************/
$router = new Router();
$router->addRoute('GET', '/',               ['App\\Controller\\SessionController', "redirect"   ]);
$router->addRoute('GET', '/log_in',         ['App\\Controller\\SessionController', "newSession" ]);
$router->addRoute('GET', '/log_out',        ['App\\Controller\\SessionController', "destroy"    ]);
$router->addRoute('GET', '/sign_up',        ['App\\Controller\\UserController',    "signUp"     ]);
$router->addRoute('GET', '/edit_user',      ['App\\Controller\\UserController',    "edit"       ]);
$router->addRoute('GET', '/account',        ['App\\Controller\\UserController',    "account"    ]);
$router->addRoute('GET', '/users' ,         ['App\\Controller\\UserController',    "users"      ]);
$router->addRoute('GET', '/upload',         ['App\\Controller\\ImageController',   "upload"     ]);
$router->addRoute('GET', '/gallery',        ['App\\Controller\\ImageController',   "gallery"    ]);
$router->addRoute('POST', '/log_in',        ['App\\Controller\\SessionController', "create"     ]);
$router->addRoute('POST', '/sign_up',       ['App\\Controller\\UserController',    "create"     ]);
$router->addRoute('POST', '/delete_user',   ['App\\Controller\\UserController',    "destroy"    ]);
$router->addRoute('POST', '/edit_user',     ['App\\Controller\\UserController',    "update"     ]);
$router->addRoute('POST', '/upload',        ['App\\Controller\\ImageController',   "save"       ]);
$router->addRoute('POST', '/delete_image',  ['App\\Controller\\ImageController',   "destroy"    ]);
// Convert i.e. "/foo%40bar?id=1" to "/[email protected]"
$uri = rawurldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$route = $router->match($_SERVER['REQUEST_METHOD'], $uri);
if ($route === null) {
    $route = [
    'handle' => ['App\\Controller\\ErrorController', 'error404'],
    'arguments' => []
    ];
}
$controller = $container->create($route['handle'][0]);
$container->call([$controller, $route['handle'][1]], $route['arguments']);

How do I run two separate Django sites based on a subdomain?

I have two Django sites. One is a staging site and the other is production. I want the staging site to be visible at beta.ialexander.io and the production one at ialexander.io. I'm using mod_wsgi with Apache. Here are the two .conf files:

ialexander.conf:

# WSGI Stuff
WSGIPythonPath /var/www/Ullmannite

<VirtualHost *:80>
  # WSGI Stuff
  WSGIScriptAlias / /var/www/Ullmannite/Ullmannite/wsgi.py

  # Identification
  ServerName ialexander.io 
  ServerAdmin [email protected]

  # Public files
  Alias /assets /var/www/Ullmannite/public

  # Logs
  ErrorLog ${APACHE_LOG_DIR}/iAlexander-Error.log
  CustomLog ${APACHE_LOG_DIR}/iAlexander-Access.log combined

  # Access
  DocumentRoot "/var/www/Ullmannite/public"

  <Directory "/var/www/Ullmannite/Ullmannite">
    <Files "wsgi.py">
      Require all granted
    </Files>
  </Directory>

  <Directory "/var/www/Ullmannite/public">
    Require all granted
  </Directory>
</VirtualHost>

000-ialexander-staging.conf:

# WSGI Stuff
WSGIPythonPath /var/www/Ullmannite-Staging

<VirtualHost *:80>
  # WSGI Stuff
  WSGIScriptAlias /beta /var/www/Ullmannite-Staging/Ullmannite/wsgi.py

  # Identification
  ServerName ialexander.io
  ServerAdmin [email protected]

  # Public files
  Alias /assets /var/www/Ullmannite-Staging/public

  # Logs
  ErrorLog ${APACHE_LOG_DIR}/iAlexander-Staging-Error.log
  CustomLog ${APACHE_LOG_DIR}/iAlexander-Staging-Access.log combined

  # Access
  DocumentRoot "/var/www/Ullmannite-Staging/public"

  <Directory "/var/www/Ullmannite-Staging/Ullmannite">
    <Files "wsgi.py">
      Require all granted
    </Files>
  </Directory>

  <Directory "/var/www/Ullmannite-Staging/public">
    Require all granted
  </Directory>
</VirtualHost>

I've been struggling with this for weeks now. Originally in 000-ialexander-staging.conf I had WSGIScriptAlias / /var/www/Ullmannite-Staging/Ullmannite/wsgi.py and ServerName beta.ialexander.io, but that didn't give me what I need. I don't remember exactly what happened because this was around two weeks ago.

Currently I have 000-ialexander-staging.conf disabled because it breaks the other one (ialexander.conf). However, when I have 000-ialexander-staging.conf enabled and I visit http://ialexander.io/beta I see the production site.

I know there's a glitch where you have to have the sites which have WSGIScriptAlias values in order. If I have the first one where WSGIScriptAlias is set to / before the second one it'll send that one, first. That's the reason I've named 000-ialexander-staging.conf with the 000- prefix. I wanted to make sure Apache is reading that one first, because it's the one that has a WSGIScriptAlias value of /beta.

Why are these things happening and how can I get the production site to return at ialexander.io but the staging one at beta.ialexander.io?

mod_rewrite htaccess ruleset with Apache/2.4.7

currently struggling with a problem writing a mod_rewrite working ruleset for my project.

I have a static website which sits on a subfolder of the project, and a single php file which handles api calls.

Options -Indexes
RewriteEngine On
RewriteBase /~ubuntu/myproject/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !upload/?$
RewriteRule ^(.*)$ static/$1 [L]

RewriteRule ^upload/?$ app/upload.php [L]

This is what I've tried so far, I am not yet familiar with mod_rewrite. This ruleset works, as long as the user doesn't type in anything which can't be mapped to any resource. When that happens it's either error 500 (too many iterations) or 404. I want to serve static files normally from the subfolder (without the user typing the full path to the website directory) and rewrite calls to mywebsite/upload/ to the php file located in app/upload.php

mod_rewrite htaccess ruleset with Apache/2.4.7

currently struggling with a problem writing a mod_rewrite working ruleset for my project.

I have a static website which sits on a subfolder of the project, and a single php file which handles api calls.

Options -Indexes
RewriteEngine On
RewriteBase /~ubuntu/myproject/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !upload/?$
RewriteRule ^(.*)$ static/$1 [L]

RewriteRule ^upload/?$ app/upload.php [L]

This is what I've tried so far, I am not yet familiar with mod_rewrite. This ruleset works, as long as the user doesn't type in anything which can't be mapped to any resource. When that happens it's either error 500 (too many iterations) or 404. I want to serve static files normally from the subfolder (without the user typing the full path to the website directory) and rewrite calls to mywebsite/upload/ to the php file located in app/upload.php

.htaccess to hide 2 folder paths

I am having difficulties getting the second statement working regarding admins, i am trying to hide both new and admin parts of the directory. new seems to be hiding fine however admin doesnt want to know. IS the first rule for new almost blocking the second one? Is it possible to have the two combined so thestatement would read if either new or admins then hide...?

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+new/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^new/)^(.*)$ /new/$1 [L,NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+admins/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^admins/)^(.*)$ /admins/$1 [L,NC]

.htaccess to hide 2 folder paths

I am having difficulties getting the second statement working regarding admins, i am trying to hide both new and admin parts of the directory. new seems to be hiding fine however admin doesnt want to know. IS the first rule for new almost blocking the second one? Is it possible to have the two combined so thestatement would read if either new or admins then hide...?

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+new/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^new/)^(.*)$ /new/$1 [L,NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+admins/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^admins/)^(.*)$ /admins/$1 [L,NC]

.htaccess to hide 2 folder paths

I am having difficulties getting the second statement working regarding admins, i am trying to hide both new and admin parts of the directory. new seems to be hiding fine however admin doesnt want to know. IS the first rule for new almost blocking the second one? Is it possible to have the two combined so thestatement would read if either new or admins then hide...?

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+new/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^new/)^(.*)$ /new/$1 [L,NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+admins/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^admins/)^(.*)$ /admins/$1 [L,NC]

.htaccess to hide 2 folder paths

I am having difficulties getting the second statement working regarding admins, i am trying to hide both new and admin parts of the directory. new seems to be hiding fine however admin doesnt want to know. IS the first rule for new almost blocking the second one? Is it possible to have the two combined so thestatement would read if either new or admins then hide...?

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+new/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^new/)^(.*)$ /new/$1 [L,NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+admins/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^admins/)^(.*)$ /admins/$1 [L,NC]

.htaccess: How do I redirect to a PHP script only when accessing a specific subdirectory?

I created a .htaccess file that redirects .png QR code requests to a PHP QR code generator.

RewriteEngine On
RewriteBase /qr/

RewriteCond %{THE_REQUEST} \ /+([^\?\ ]+)\.png
RewriteRule ^(.*)$ access-code.php?id=%1 [QSA,L]

It works well for the original intent, but also sends EVERY .png request to the same script. I need to alter the RewriteCond to only accept .png files if in the /qr/access-code/* directory.

I placed the .htaccess file in the following directory:

/qr/.htaccess

Example request that works well as intended (not an actual link):

http://mywebsite.com/qr/access-code/12345678.png

Example request that "works", but I don't want it to get redirected:

http://mywebsite.com/qr/img/background.png (not an actual link)

How can I adjust my .htaccess condition to make my rule function as intended?

.htaccess: How do I redirect a .png to a .php script only if accessing a specific subdirectory?

I created a .htaccess file that redirects .png QR code requests to a PHP QR code generator.

RewriteEngine On
RewriteBase /qr/

RewriteCond %{THE_REQUEST} \ /+([^\?\ ]+)\.png
RewriteRule ^(.*)$ access-code.php?id=%1 [QSA,L]

It works well for the original intent, but also sends EVERY .png request to the same script. I need to alter the RewriteCond to only accept .png files if in the /qr/access-code/* directory.

I placed the .htaccess file in the following directory:

/qr/.htaccess

Example request that works well as intended (not an actual link):

http://mywebsite.com/qr/access-code/12345678.png

Example request that "works", but I don't want it to get redirected:

http://mywebsite.com/qr/img/background.png (not an actual link)

How can I adjust my .htaccess condition to make my rule function as intended?