Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect all requests to index.php

I have a root folder /var/www/minus_project and only two files in it: index.php and .htaccess.

How to make apache2 redirect all requests like localhost.com/minus_project/some/url/here/... to index.php? My apache2 configuration

<VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot /var/www/html
        Alias /phpinfo /var/www/phpinfo
        Alias /minus_project /var/www/minus_project

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
like image 795
Vahag Chakhoyan Avatar asked Dec 08 '16 18:12

Vahag Chakhoyan


1 Answers

Here is how you create an alias and route everything to index.php inside aliased directory.

Alias /minus_project /var/www/minus_project

<Directory /var/www/minus_project>
   Options Indexes FollowSymLinks MultiViews ExecCGI
   AllowOverride All
   Order allow,deny
   Allow from all
   Require all granted

   RewriteEngine On
   RewriteBase /minus_project/

   RewriteRule ^/index\.php$ - [L,NC]

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule . index.php [L]
</Directory>

Place above snippet inside VirtualHost section and don't forget to restart Apache server.

like image 161
anubhava Avatar answered Sep 24 '22 21:09

anubhava