Contents
1 — Enabling mod_rewrite
sudo a2enmod rewrite sudo systemctl restart apache2
2. 创建2个 .htaccess file 一个放在根目录一个放在web目录
<IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On </IfModule> <IfModule mod_rewrite.c> RewriteCond %{REQUEST_URI} ^/.* RewriteRule ^(.*)$ web/$1 [L] RewriteCond %{REQUEST_URI} !^/web/ RewriteCond %{REQUEST_FILENAME} !-f [OR] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ web/index.php </IfModule>
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php
3. In config/web.php
'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ // Your rules here ], ],
4.apache2.conf
vi /etc/apache2/apache2.conf
<Directory /var/www/html/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
5. restart apache2
systemctl restart apache25181