WordPress URL在NGINX服务器上重写(无HTACCESS)

发布于 2025-02-14 01:33:55 字数 900 浏览 0 评论 0原文

我最近了解到,我无法使用.htaccess文件在Nginx服务器上重定向和重写URL。我正在将20,000页的.html网站迁移到WordPress,并且必须保留永久链接结构并添加重定向以维护SEO。

我要完成的只是两件事:

  1. 将301重定向添加到.html页面,将它们指向其.php对应物
  2. 从页面URL中删除'/public_html/'文件夹 www.website.com/public_html/ www.website.com/ [affiliate]

我已经能够通过301个REDIRECTS通过301个REDIRECTS插件目前,但是我不确定如何从URL中删除文件夹。我可以将会员文件夹放在根目录中,而不必这样做,但它会极大地弄乱我的工作空间。

这是我目前重写URL的尝试(在site.conf.hbs中---这是正确的文件吗?)

    #
    # Rewrite public_html out of url when visiting affiliate pages
    #
    location /public_html
    {
        rewrite ^(/public_html/.*)/(\w+).php /$2.php last;
    }

。 PHP重定向目前正在通过插件工作,但是我想通常将其添加以消除插件。

谢谢!

I've recently learned that I'm unable to use the .htaccess file to redirect and rewrite url's on an NGINX server. I'm in the process of migrating a 20,000 page .html website to wordpress, and must preserve the permalink structure and add redirects to maintain the SEO.

All I am trying to accomplish are two things:

  1. Add a 301 redirect to .html pages that will point them to their .php counterparts
  2. Remove the '/public_html/' folder from the page URL
    www.website.com/public_html/[affiliate] => www.website.com/[affiliate]

I have been able to implement the 301 redirects via plugin for now, however I'm unsure how to go about removing the folder from the URL. I could place the affiliate folders in the root directory and not have to do this, but it will clutter up my workspace immensely.

This is my current attempt at rewriting the url (in site.conf.hbs --- is this the correct file?)

    #
    # Rewrite public_html out of url when visiting affiliate pages
    #
    location /public_html
    {
        rewrite ^(/public_html/.*)/(\w+).php /$2.php last;
    }

Any help is much appreciated! The php redirect is working via plugin for now, but I'd like to just add it as a rule to get rid of the plugin if possible.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文