【问题标题】:How to remove post page number in the URL如何删除网址中的帖子页码
【发布时间】:2020-06-05 23:29:34
【问题描述】:

我用的是wordpress,wordpress有这个功能可以让你把一篇文章分成多页。

我现在遇到的问题是,当用户导航到第 2 页时,URL 将变为 www.domain.com/post-title/2/ 而不是留在 www.domain.com/domain-title/

澄清一下,因为我在较长的帖子中使用了下一页短代码,所以对于 1 篇帖子,我会说...几页,例如:

http://www.domain.com/post1/ http://www.domain.com/post1/1/ http://www.domain.com/post1/2/ http://www.domain.com/post1/3/

无论在哪个帖子页面上,我都希望它只读取http://www.domain.com/post1/

顺便说一句,我正在使用 Nginx。谢谢!

【问题讨论】:

标签: wordpress nginx rewrite


【解决方案1】:

这是我的 nginx wordpress 配置

server {
        listen 80;
        server_name domain.com;
        server_tokens   off;
        root /path/to/root;
        access_log /var/log/nginx/wordpress_access.log;
        error_log /var/log/nginx/wordpress_error.log;
        index index.php;
        charset utf-8;
        gzip on;
        gzip_disable "msie6";

        location / {
                try_files $uri /index.php$request_uri;
        }
        location ~ \.php {
                include fastcgi_params;
                # change according to ur sock/port 
                fastcgi_pass   unix:/var/run/php5-fpm.sock;
        }
        location ~ /\.ht {
                deny all;
        }
}

然后转到永久链接配置页面http://domain.com/wp-admin/options-permalink.php 并更改您的永久链接设置

【讨论】:

  • 谢谢,但这并不是我真正要问的。我的永久链接正在运行,这意味着我已经获得了像 www.domain.com/post-title 这样的 URL。但是,问题是如果我将帖子分成页面,它会显示页码,我不希望这样。
  • 你想在第二页,而不是在网址中显示2
  • 没错。因为用户在第 2 页时会分享我的帖子,而看到链接的人会到达第 2 页。这很奇怪不是吗? :)
  • 好吧,问题是,如果没有那个页码,服务器不会知道你在哪个页面上,你使用自己的分享按钮吗?您可以尝试配置这些。
  • 这只是重写,不是吗?我的意思是,它仍然会加载 www.domain.com/page-title/2,但随后会在地址栏中显示 www.domain.com/page-title。我想这更像是一个 nginx 游戏,但我在重写正则表达式时非常糟糕:-/
猜你喜欢
  • 1970-01-01
  • 2015-07-11
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
相关资源
最近更新 更多