Home >PHP Framework >YII >How to remove index.php in yii
Yii method to remove index.php: first enable "apache-rewrite" in "httpd.conf"; then restart Apache; then modify the configuration "main.php"; and finally in the same directory as the entry file Just add the ".htaccess" file.
Recommended: "yii Tutorial"
yii2 Method to remove index.php
1. Turn on apache-rewrite
Under Windows, we usually use the Administrator account, so it is very simple to enable these two items:
In Find
#LoadModule rewrite_module modules/mod_rewrite.so
in [Apache installation directory]/conf/httpd.conf and remove the preceding comment symbol #. If this line doesn't exist, add it. And confirm whether the file mod_rewrite.so exists in the modules folder in the apache installation directory. This enables the Mod Rewrite feature.
Find
Options FollowSymLinks AllowOverride None Order deny,allow Deny from all
in [Apache installation directory]/conf/httpd.conf and set
“AllowOverride None ”改成“ AllowOverride All ”,
so that all folders support .htaccess, or for the specified To enable .htaccess in the folder, you can add Options Indexes FollowSymLinks in [Apache installation directory]/conf/httpd.conf AllowOverride All Order allow,deny Allow from all This approach is generally configured with the virtual host, so most will Write the above configuration code into [Apache installation directory]/conf/extra/httpd-vhost.conf, which will be clearer and easier to manage.
After restarting Apache, it will be ok.
After completing the appeal steps, use link settings other than the default in WordPress's fixed link. WordPress will directly generate the corresponding .htaccess in its installation directory, so that you can use the set link form.
2. Modify the configuration main.php
'urlManager'=>[ 'enablePrettyUrl' => true, 'showScriptName' => false, //路由管理 'rules' => [ "<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>"=>"<module>/<controller>/<action>", "<controller:\w+>/<action:\w+>/<id:\d+>"=>"<controller>/<action>", "<controller:\w+>/<action:\w+>"=>"<controller>/<action>", ], ],
3. Add the .htaccess file in the same directory as the entry file
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 method has been tested by myself and is effective. Just follow the steps.
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!