Home > Operation and Maintenance > Nginx > How to configure nginx to support .htaccess files to achieve pseudo-static

How to configure nginx to support .htaccess files to achieve pseudo-static

PHPz
Release: 2023-05-14 08:19:05
forward
2454 people have browsed it

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:
How to configure nginx to support .htaccess files to achieve pseudo-static

##include /var/www/html/168pc/bbs/.htaccess; (change this to the specific location of your .htaccess file)

wqSave and exit.

5. Reload the nginx configuration file:

Copy the code The code is as follows:

/etc/init.d/nginx reload

Reopen the web page to see Look, if the pseudo-static is normal, it proves that your rewrite rule syntax is correct.


How to configure nginx to support .htaccess files to achieve pseudo-static

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template