yii2 apache2 开启pretty url

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 apache2

http://www.waitingfy.com/archives/5181

5181

Leave a Reply

Name and Email Address are required fields.
Your email will not be published or shared with third parties.