Searching for information on Many people said that nginx currently does not support .htaccess files. I tested it according to nginx rules and found that nginx fully supports .htaccess files!
The method is as follows:
1. Create a new .htaccess file in the directory where you need to use the .htaccess file,
such as one of my discuz forum directories:
Copy code The code is as follows:
vim /var/www/html/168pc/bbs/.htaccess
2. Enter the rules in it. I enter the pseudo-static rules of discuz here:
Copy code The code is 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=$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
wqSave and exit.
3. Modify the nginx configuration file:
vim /etc/nginx/nginx.conf
4. Introduce it into server{} where you need to add a pseudo-static virtual host .htaccess file, as shown in the picture:
The above is the detailed content of How to configure nginx to support .htaccess files to achieve pseudo-static. For more information, please follow other related articles on the PHP Chinese website!