要实现一个文章页面跳转到其他二级域名的 Nginx 伪静态规则,可以使用 Nginx 的 rewrite 指令。

假设你的文章页面的 URL 为:https://example.com/article/page.html,要跳转到其他二级域名:https://subdomain.example.com/page.html。

在 Nginx 的配置文件中,你可以添加以下规则:

server {
    listen 80;
    server_name example.com;

    location /article/ {
        rewrite ^/article/(.*)$ https://subdomain.example.com/$1 permanent;
    }
}

这个配置中,设置了监听 80 端口,并指定了服务器名为 example.com。在 location /article/ 块中,使用 rewrite 指令将 /article/ 后面的路径捕获到 $1 变量中,并构造新的 URL https://subdomain.example.com/$1。

注意,这里使用了 permanent 关键字,表示进行永久重定向。如果想要临时重定向,可以使用 redirect 关键字。

另外,记得重启或重新加载 Nginx 配置以使修改生效。

Nginx 伪静态规则:实现文章页面跳转到二级域名

原文地址: https://www.cveoy.top/t/topic/qpQG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录