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;
}

 

posted @   黄文Rex  阅读(219)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示