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:
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.