Today on the Internet Baidu read a lot of articles, want to get rid of index.php entrance file There are many ways, I also follow the site to the root directory to create a new. htaccess file, the contents are as follows:
Rewriteengine on
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-d
Rewritecond $!^ (index\.php|images|robots\.txt)
Rewriterule ^ (. *) $/index.php/$1 [L]
It means:
- The first line, setting the Rewriteengine engine to On, is for URL rewriting to take effect;
- The second line, if the file exists, directly access the file, do not carry out the following rewriterule.
- Third row, if the directory exists, direct access to the directory is not rewriterule
Similarly: Rewritecond%{request_uri}!^.* (\.css|\.js|\.gif|\.png|\.jpg|\.jpeg) $ #如果是这些后缀的文件, directly
Access to the file without rewrite
- Line four, configure URL rewrite rules,!^ (index\.php|images|robots\.txt) This regular expression indicates which files do not need to be rewritten, but direct access;
- Line five, ^ (. *) $ is a regular expression, which means that all requests are sent to/index.php/$1, and anyone familiar with the URL knows that a backslash (/) begins with a relative path, relative to whom? Root, which is the URL.
Originally to the site access to the URL is such to://URL/index.php?/controller/function, now want to remove index.php?, here index.php back also a question mark, good annoying, the results of the document was built, input URL access, reported Nginx 404 error, my nginx is 1.4.7 version
Later through the multi-party search, finally fix, open nginx to the configuration file nginx.conf, add the following command in the server section
if (!-e $request _filename) {
Rewrite ^.*$/index.php last;
}
After saving, restart Nginx (/etc/init.d/nginx restart), and then enter the URL without index.php?, really to be able to access the
Transferred from: http://www.350351.com/qianyanjishu/webkaifa/153745.html
Delete ci frame in CentOS nginx environment index.php Portal encounters 404 Issues