将所有请求重定向到index.php

时间:2016-12-08 18:41:26

标签: apache .htaccess redirect

我有一个根文件夹 / var / www / minus_project ,其中只有两个文件: index.php .htaccess 。< / p>

如何让apache2将所有请求重定向到 localhost.com/minus_project/ some / url / here /... 到index.php? 我的apache2配置

<VirtualHost *:80>
        ServerAdmin webmaster@localhost.com
        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>

1 个答案:

答案 0 :(得分:3)

以下是创建别名的方法,并将所有内容路由到别名目录中的index.php

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>

将上方代码段放在VirtualHost部分内,不要忘记重启Apache服务器。