Nginx support. htaccess file to achieve pseudo static method sharing _nginx

Source: Internet
Author: User

in the Google search For information many people say nginx currently do not support. htaccess file, I followed the rules of Nginx test, and found that Nginx is fully supported. htaccess file!

The method is as follows:

1. Create a new. htaccess file in the directory where you need to use the. htaccess file.
As one of my Discuz forum directory:

Copy Code code as follows:
Vim/var/www/html/168pc/bbs/.htaccess

2. Enter the rules here, I enter the pseudo static rules for Discuz:

Copy Code code as follows:

# nginx Rewrite rule
Rewrite ^ (. *)/archiver/((Fid|tid)-[w-]+.html) $ $1/archiver/index.php?$2 last;
Rewrite ^ (. *)/forum-([0-9]+)-([0-9]+). html$ $1/forumdisplay.php?fid=$2&page=$3 last;
Rewrite ^ (. *)/thread-([0-9]+)-([0-9]+)-([0-9]+). html$ $1/viewthread.php?tid=$2&extra=page%3d$4&page=$3 Last
Rewrite ^ (. *)/profile-(USERNAME|UID)-(. +). html$ $1/viewpro.php?$2=$3 last;
Rewrite ^ (. *)/space-(USERNAME|UID)-(. +). html$ $1/space.php?$2=$3 last;
Rewrite ^ (. *)/tag-(. +). html$ $1/tag.php?name=$2 last;
# End Nginx Rewrite rule

Wq Save exit.

3. Modify Nginx configuration file:

Vim/etc/nginx/nginx.conf

4. The. htaccess file is introduced in the server{} that requires the addition of pseudo static virtual hosts, as shown in the figure:

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

Wq Save exit.

5. Reload the Nginx configuration file:

Copy Code code as follows:
/etc/init.d/nginx Reload

Reopen the page to see if the pseudo static is normal to prove that your rewrite rule syntax is correct.

Normal, complete!

add : I found online to automatically convert Apache rewrite pseudo static rules to Nginx rewrite Web pages. We can try.

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

The contents of this address contain the ability to complete the modifications described above. is to automatically convert the rules in. htaccess to the rules available under Nginx.

Summary :.

The htaccess file, originally a distributed configuration file for Apache, provides a way to change the configuration for each directory by placing a file containing instructions in a specific directory, with instructions for this directory and all its subdirectories. In fact, Nginx can also use the. htaccess file to implement a variety of functions. Realizing pseudo Static is just one of the uses of. htaccess,. Htaccess can also do many uses, such as filtering access to IP, setting Web Directory access rights, passwords, and so on.

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.