URL美化 2016.11.28

apache配置

1、开启rewrite module:

a2enmod rewrite
sudo service apache2 restart

2、修改apache配置文件:

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
RewriteEngine on

AllowOverride All
Order allow,deny
allow from all

Yii2配置:

1、配置config/web.php

'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'showScriptName' => false,
'suffix' => '.html',
'rules' =>[
'//' => '//view',
'/' => '/view',
]
],

2、添加 web/.htaccess文件:

Options +FollowSymLinks
IndexIgnore /
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php

你可能感兴趣的:(URL美化 2016.11.28)