Delete ci frame in CentOS nginx environment index.php Portal encounters 404 Issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.