请问Nginx如何设置伪静态?
不同程序在不同运行环境下, apache 、nginx、iis下的伪静态规则都存在差异。
以下只是举例,具体需要结合自己的网站程序配置
server { listen 80; server_name yourdomain.com; root /var/www/yourdomain.com; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据你的 PHP 版本调整 } # 通用伪静态规则 rewrite ^/archive/([0-9]{4})/([0-9]{2})/([0-9]{2})/$ /index.php?year=$1&month=$2&day=$3 last; rewrite ^/category/(.*)/$ /index.php?category=$1 last; rewrite ^/tag/(.*)/$ /index.php?tag=$1 last; rewrite ^/page/([0-9]+)/$ /index.php?page=$1 last; rewrite ^/post/([0-9]+)$ /index.php?post_id=$1 last; }
更新时间:2025-04-10 23:45:59
下一篇:请问MySQL密码忘记怎么办?
转载请注明原文链接:https://www.muzicopy.com/suibi/3475.html