Home > PHP Framework > YII > How to remove index.php in yii

How to remove index.php in yii

藏色散人
Release: 2020-08-10 10:14:28
Original
2047 people have browsed it

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.

How to remove index.php in yii

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
Copy after login

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
Copy after login

in [Apache installation directory]/conf/httpd.conf and set

“AllowOverride None
”改成“
AllowOverride All
”,
Copy after login

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>",
],
],
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template