URL美化 2016.11.28

2016-11-29  本文已影响0人  yeqingwen

apache配置

1、开启rewrite module:

a2enmod rewrite
sudo service apache2 restart

2、修改apache配置文件:

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
RewriteEngine on
<Directory /var/www/html>
AllowOverride All
Order allow,deny
allow from all
</Directory>

Yii2配置:

1、配置config/web.php

'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'showScriptName' => false,
'suffix' => '.html',
'rules' =>[
'<module:\w+>/<controller:\w+>/<id:\d+>' => '<module>/<controller>/view',
'<controller:\w+>/<id:\d+>' => '<controller>/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

上一篇 下一篇

猜你喜欢

热点阅读