Nginx如何设置伪静态?

COS、CDN

不同程序在不同运行环境下, 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; }

 

COS、CDN
热门