Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article is a detailed introduction to "how to configure nginx to support.htaccess files to achieve pseudo-static". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to configure nginx to support.htaccess files to achieve pseudo-static" can help you solve your doubts. The following is a detailed introduction to learn new knowledge together.

Many people say that nginx does not support.htaccess files at present. I tried 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 want to use the.htaccess file,

Such as one of my discuz forum directory:

The copy code is as follows:

vim /var/www/html/168pc/bbs/.htaccess

2. Enter the rule in there, and I'll enter the pseudo-static rule of discuz here:

The copy 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%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 the nginx configuration file:

vim /etc/nginx/nginx.conf

4. Add the.htaccess file to the server{} that needs to add 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 nginx configuration file:

The copy code is as follows:

/etc/init.d/nginx reload

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

Read here, this article "how to configure nginx to support.htaccess file pseudo-static" article has been introduced, want to master the knowledge points of this article also need to be used by yourself to understand, if you want to know more related content of the article, welcome to pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report