Yii method to remove index.php: 1. Enable the mod_rewrite module of apache and restart apache; 2. Edit the /config/web.php file in the project; 3. At the same level as the index.php file Add the [.htaccess] file to the directory.
Specific method:
(Recommended tutorial: php graphic tutorial)
1. Enable apache's mod_rewrite module
Remove the "#" symbol before LoadModule rewrite_module modules/mod_rewrite.so
Ensure DocumentRoot "/Library/WebServer /Documents"
Restart apache, command: sudo apachectl restart
2. Add code to /config/web.php in the project:
components'=>array( ... 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ], ], )
(Video tutorial recommendation: php video tutorial)
3. Add the file ".htaccess" in the same directory as the index.php file (/web/) with the following content:
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
The above is the detailed content of How to remove index.php in yii. For more information, please follow other related articles on the PHP Chinese website!