我有一个根文件夹 / 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>
答案 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服务器。