Nginx does not support. htaccess Solutions

Source: Internet
Author: User

Probably a lot of friends are commonly used nginx does not support. htaccess, only Apache supports. htaccess file, in fact this is the wrong view Nginx is also supported. Hatccess Oh, let me give you a summary of the configuration method.

In fact, Nginx and. htaccess a little relationship, just a lot of people by the influence of Apache think Nginx should also support. htaccess function. Just include the. htaccess file directly in the Nginx configuration.

Include/Site Directory/.htaccess;

How simple, but more people laugh and cry is that most people do not know Nginx and Apache is two different webserver program, so many people do: in Nginx include. htaccess file, Upload Apache pseudo-static rules of. htaccess to the site root directory ... No words. In fact, Nginx can include any file, not just. htaccess.

In fact, Nginx is quoted as such. htaccess and Apache are still different:

1, Nginx is started to introduce, because Nginx special focus on efficiency, so when the start will be all the configuration file read into memory, and then start a. If a syntax error is found, the startup fails. Apache is dynamically introduced, and each visit to the site is re-loaded into the configuration.

2, the include in Nginx is manually added, specify the directory. Apache has used the. htaccess as a feature mechanism, and all subdirectories of the support station can have. htaccess files.

The actual development experience, many people in the early days are more virtual space, and the early virtual space is basically Apache do webserver, so users do not need to contact the space quotient can do their own pseudo-static, and open source program is more convenient to expand this function (Ecshop,wordpress, PHPCMS, etc.). and maintenance is also convenient, as long as the cover. Htaccess is fine.

In fact, few sites often go to modify. htaccess, and now basically use VPS mostly.

Nginx can also use the. htaccess file for a variety of functions.

Introduce the. htaccess file in Nginx/nginx.conf's server{}:
include/vhosts/quany.info/.htaccess;

Nginx can fully support the. htaccess file, please do the following:

1. Create a new. htaccess file, enter the rules, such as the site's rules:

The code is as follows Copy Code

# nginx Rewrite rule
Rewrite ^ (. *?) /article/.*?-(d+)-(d+). html$ $1/show.html?id=$2&page=$3 break;
Rewrite ^ (. *?) /category/.*?-(d+)-(d+). html$ $1/list.html?id=$2&page=$3 break;
Rewrite ^ (. *?) /tag/([^/]+)/?$ $1/tag.html?w=$2 break;
Rewrite ^ (. *?) /tag/([^/]+)/(d+) $ $1/tag.html?w=$2&page=$3 break;
# End Nginx Rewrite rule

Save the file and upload it to the root directory of the Web site.

2. Modify the virtual host configuration

The code is as follows Copy Code
# ee/usr/local/etc/nginx/nginx.conf

#freebsd 7.2 Default Nginx configuration file installed by default
Introduce the. htaccess file in the server block in the virtual machine that you need to add pseudo-static

The code is as follows Copy Code
Include/usr/www/.htaccess

#请把这个改成你 the location of the. htaccess file,
Save, Exit restart Nginx

The code is as follows Copy Code
#/usr/local/etc/rc.d/nginx Restart

Refresh See if you can normal the grammar of your rewrite rule is correct from proving your

Nginx Rewrite rules you can be placed directly in the host configuration can also be placed in a separate file with Includeinru, saved as a separate file, save to a new file (file name can be arbitrary, but it is recommended to use. HT (Note that there is a "dot") to start the file name, Because this server is filtered by default, external file access to. HT begins:

The code is as follows Copy Code

Location ~/.ht {
Deny all;
}

Nginx does not support. htaccess Solutions

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.