简体   繁体   English

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

[英]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 . 我有一个根文件夹/ var / www / minus_project ,其中只有两个文件: index.php.htaccess

How to make apache2 redirect all requests like localhost.com/minus_project/ some/url/here/... to index.php? 如何使apache2将所有请求(如localhost.com/minus_project/ some / url / here / ...)重定向到index.php? My apache2 configuration 我的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>

Here is how you create an alias and route everything to index.php inside aliased directory. 这是创建别名并将所有内容路由到别名目录中的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>

Place above snippet inside VirtualHost section and don't forget to restart Apache server. 将其放在VirtualHost部分中的代码段上方,不要忘记重启Apache服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM