Vahag Chakhoyan
Vahag Chakhoyan

Reputation: 779

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>

Upvotes: 7

Views: 15807

Answers (1)

anubhava
anubhava

Reputation: 786091

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.

Upvotes: 8

Related Questions