Nginx supports. htaccess file implementation Pseudo-static method

Source: Internet
Author: User

Here's how:

1. Create a new. htaccess file in the directory where you want to use the. htaccess file,

Vim/var/www/html/.htaccess

2. Enter the rules inside and I'll enter the pseudo-static rules for Discuz:

# nginx Rewrite rule
Rewrite/!. (JS|GIF|JPG|PNG|CSS) $/index.php;
# End Nginx Rewrite rule

Wq Save exit.

3. Modify the Nginx configuration file:

Vim/etc/nginx/nginx.conf

4. Introduce the. htaccess file in server{} that requires the addition of pseudo-static virtual hosts:

server {        listen       8081;        server_name  localhost;        #charset Koi8-r;        #access_log  logs/host.access.log  main;        Location/{            #root   html;root   d:/www; include d:/www/.htaccess;            Index  index.php,index.phtml,index.html index.htm;if (!-e $request _filename) {rewrite ^/(. *) $/index.php last;}        } Location ~ \.ht {deny all  ;} # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {  root           d:/www;  Fastcgi_pass   127.0.0.1:9000;  Fastcgi_index  index.php;  Fastcgi_param  script_filename  $document _root$fastcgi_script_name;  Include        Fastcgi_params;}}

  

Include/var/www/html/.htaccess (change this to the exact location of your. htaccess file)

Wq Save exit.

5. Reload the Nginx configuration file:

/etc/init.d/nginx Reload

Re-open the Web page and see if pseudo-static normal proves that your rewrite rule syntax is correct.

Normal, finished!

Add: I found on the Internet an Apache rewrite pseudo-static rules can be automatically converted to Nginx rewrite Web page. We can try it.

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

The contents of this address include the ability to complete the above-mentioned minor modifications. is to automatically convert the rules in. htaccess to the rules available under Nginx.

Summary: the. htaccess file was originally a distributed configuration file for Apache, providing a way to change the configuration for each directory, that is, to place a file containing instructions in a particular directory, where the instructions are applied to this directory and all its subdirectories. In fact, to modify the Nginx can also use the. htaccess file for a variety of functions. Implementing pseudo-Static is just one of the purposes of. Htaccess. Htaccess can also do a lot of purposes, such as filtering access to IP, setting Web Directory access permissions, passwords, and so on.

Nginx supports. htaccess file implementation Pseudo-static method

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.