Convert Apache. htaccess to Nginx

Source: Internet
Author: User
Tags nginx server

1, the original site in the WAMP environment to complete, all normal, uploaded to the virtual host environment for LNMP, the results can open the home page, and then click on other pages all reported 404 errors;

2, analyzed the reason: the original site environment for WAMP used pseudo-static, Pseudo-static rules are written in the. htaccess file in the root directory of the Web site, and Apache recognizes the file contents by default, and the Nginx server does not recognize the. htaccess file, causing the pseudo-static rule to be invalid, naturally unable to resolve the URL address, resulting in a 404 error (the file does not exist)

3, the solution: Because the Nginx server does not recognize the. htaccess file, so the pseudo-static rules originally written in this file need to be transferred out, there are two ways of transfer:

Method One, if you want to retain the. htaccess file, create a pseudo-static rule configuration file name in the Linux server directory/usr/local/nginx/conf/rewrite/, for example:/usr/local/nginx/conf/ rewrite/my.conf, convert the rewrite rule in the. htaccess file to the rewrite rule under Nginx and provide an auto-convert URL

http://www.anilcetin.com/convert-apache-htaccess-to-nginx/measured real useful

CentOS 6.2 Combat Deployment nginx+mysql+php http://www.linuxidc.com/Linux/2013-09/90020.htm

Using Nginx to build a Web server http://www.linuxidc.com/Linux/2013-09/89768.htm

Build linux6.3+nginx1.2+php5+mysql5.5-based Web server whole process http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 under Nginx performance tuning http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 Under the configuration Nginx load ngx_pagespeed module http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 Installation Configuration nginx+pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx build video-On-demand server (simulation professional streaming software) http://www.linuxidc.com/Linux/2012-08/69151.htm

The original rules of this case
:

<ifmodule mod_rewrite.c>
Rewriteengine on
Rewritecond%{request_filename}!-d
Rewritecond%{request_filename}!-f
Rewriterule ^ (. *) $ index.php/$1 [qsa,pt,l]
</IfModule>

After conversion into Nginx
:

if (!-d $request _filename) {
Set $rule _0 1$rule_0;
}
if (!-f $request _filename) {
Set $rule _0 2$rule_0;
}
if ($rule _0 = "21") {
Rewrite ^/(. *) $/index.php/$1 last;
}

Then replace the converted rule with the. htaccess file contents and import the. htaccess file into the my.conf,my.conf content as follows:

Location/{

include/home/wwwroot/dijin.com/web/.htaccess;

}

--to complete the pseudo-static transfer

Method Two, if you do not want to retain the. htaccess file, the previous steps as usual, the last step of replacing the time to directly put the converted content into the my.conf file, as follows:

Location/{

if (!-d $request _filename) {
Set $rule _0 1$rule_0;
}
if (!-f $request _filename) {
Set $rule _0 2$rule_0;
}
if ($rule _0 = "21") {
Rewrite ^/(. *) $/index.php/$1 last;
}

}

Convert Apache. htaccess to Nginx

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.