# 将 vBulletin URL 重定向到 Discourse URL

**URL:** https://meta.discourse.org/t/redirect-vbulletin-urls-to-discourse-urls/47394
**Category:** Migrating to Discourse
**Tags:** how-to
**Created:** [2016年七月16日 12:04 UTC](https://meta.discourse.org/t/redirect-vbulletin-urls-to-discourse-urls/47394 "2016-07-16T12:04:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [2016年七月16日 12:04 UTC](https://meta.discourse.org/t/redirect-vbulletin-urls-to-discourse-urls/47394/1 "2016-07-16T12:04:33Z")

</div>

从 vBulletin 迁移到 Discourse，并希望将旧的 vBulletin URL 重定向到新的 Discourse URL？请继续阅读！

> 🔔 如果您的旧论坛和新论坛的基础 URL 相同，请改用以下教程：

> [Redirect old forum URLs to new Discourse URLs using permalinks](https://meta.discourse.org/t/redirecting-old-forum-urls-to-new-discourse-urls/20930?u=techapj)

本教程假设：

- vBulletin 基础 URL：`www.example.com/forum`

- Discourse 基础 URL：`forum.example.com`

- `www.example.com` 使用 Nginx 服务器

让我们开始吧！

### 生成 Nginx 映射文件

为了设置分类和主题的重定向，我们将使用 Nginx 的 [map 模块](http://nginx.org/en/docs/http/ngx_http_map_module.html)。在执行导入时，将通过 [`create_permalink_file`](https://github.com/discourse/discourse/blob/main/script/import_scripts/vbulletin.rb#L961-L985) 方法生成 CSV 文件（`script/import_scripts/vb_map.csv`）。我们将把 CSV 文件的内容粘贴到服务器上的映射文件中。

文件示例内容：

```plaintext
...
/forum/forumdisplay.php?6 http://forum.example.com/c/games;
/forum/forumdisplay.php?7 http://forum.example.com/c/movies;
/forum/forumdisplay.php?13 http://forum.example.com/c/admin;
/forum/showthread.php?1 http://forum.example.com/t/x/22;
/forum/showthread.php?2 http://forum.example.com/t/x/23;
/forum/showthread.php?3 http://forum.example.com/t/x/24;
/forum/showthread.php?4 http://forum.example.com/t/x/25;
...

```

将生成的 CSV 文件的完整内容复制到 `www.example.com` 服务器上的 `etc/nginx/vb_forum.map` 文件中。

### 编辑 `nginx.conf`

编辑 `/etc/nginx/nginx.conf` 文件，在 `http` 块中添加以下代码：

```plaintext
map_hash_bucket_size 128;
map_hash_max_size 80000;

map $request_uri $new {
    include /etc/nginx/vb_forum.map;
}

server {
    listen 80;
    server_name www.example.com;

    location ~ ^/forum\\/showthread.php {
        if ($args ~* ^(\\d+)-(.+)$) {
            set $tid $1;
            set $args '';
            rewrite ^ /forum/showthread.php?$tid permanent;
        }
        if ($args ~* ^t=(\\d+)$) {
            set $tid $1;
            set $args '';
            rewrite ^ /forum/showthread.php?$tid permanent;
        }
        return 301 http://forum.example.com;
    }

    location ~ ^/forum\\/forumdisplay.php {
        if ($args ~* ^(\\d+)-(.+)$) {
            set $tid $1;
            set $args '';
            rewrite ^ /forum/forumdisplay.php?$tid permanent;
        }
        if ($args ~* ^f=(\\d+)$) {
            set $tid $1;
            set $args '';
            rewrite ^ /forum/forumdisplay.php?$tid permanent;
        }
        return 301 http://forum.example.com;
    }

    if ($new) {
        rewrite ^ $new permanent;
    }

    location /forum {
        return 301 http://forum.example.com;
    }
}

```

`map_hash_max_size` 需要根据映射文件中存在的 URL 数量进行调整。

### 验证 `nginx.conf`

验证您的 Nginx 配置文件：

```plaintext
nginx -c /etc/nginx/nginx.conf -t

```

重新加载 Nginx 配置以包含您的更改：

```plaintext
sudo systemctl reload nginx

```

尝试访问 `www.example.com/forum`，您现在应该会被重定向到 `forum.example.com`。🎉

以下类型的 URL 将由上述 Nginx 配置处理：

- `www.example.com/forum` –\u003e `forum.example.com`

- `www.example.com/forum/forumdisplay.php?6` –\u003e `forum.example.com/c/games`

- `www.example.com/forum/forumdisplay.php?6-Games` –\u003e `forum.example.com/c/games`

- `www.example.com/forum/forumdisplay.php?f=6` –\u003e `forum.example.com/c/games`

- `www.example.com/forum/showthread.php?2` –\u003e `forum.example.com/t/topic-slug/23`

- `www.example.com/forum/showthread.php?2-topic-slug` –\u003e `forum.example.com/t/topic-slug/23`

- `www.example.com/forum/showthread.php?t=2` –\u003e `forum.example.com/t/topic-slug/23`

---

<div class="post-metadata">

### Author: ![webdawe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/webdawe/32/121229_2.png) [@webdawe](https://meta.discourse.org/u/webdawe)
#### Post date: [2017年三月16日 12:49 UTC](https://meta.discourse.org/t/redirect-vbulletin-urls-to-discourse-urls/47394/2 "2017-03-16T12:49:38Z")

</div>

Hi Arpit,

I have implemented your method and its working fine. But the problem is when I rebuild the app again all my nginx changes getting lost. please advise

Anil

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2017年三月16日 14:28 UTC](https://meta.discourse.org/t/redirect-vbulletin-urls-to-discourse-urls/47394/3 "2017-03-16T14:28:12Z")

</div>

The sample assumes that you’ll do the redirects on the old server, not the Discourse server.

If your discourse server is using the same name as your old server, you want to use permalink redirects, and perhaps permalink normalizations in discourse.

---

<div class="post-metadata">

### Author: ![webdawe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/webdawe/32/121229_2.png) [@webdawe](https://meta.discourse.org/u/webdawe)
#### Post date: [2017年三月20日 00:35 UTC](https://meta.discourse.org/t/redirect-vbulletin-urls-to-discourse-urls/47394/4 "2017-03-20T00:35:14Z")

</div>

Thanks @pfaffman.  
I used Permalink.create and solved the problem

> [@Redirect old forum URLs to new Discourse URLs using permalinks](https://meta.discourse.org/t/redirecting-old-forum-urls-to-new-discourse-urls/20930):
>
> Redirecting Old Forum URLs to New Discourse URLs using permalinks If you’ve moved from other forum software to Discourse using [one of our import scripts](https://github.com/discourse/discourse/tree/main/script/import_scripts), then you probably want all your hard-earned Google search results to continue pointing to the same content. Discourse has a built-in way to handle this for you as an alternative to writing nginx rules, using the permalinks lookup table. The permalinks table allows you to set two things: a url to match, and what that url should show. There a…

---

<div class="post-metadata">

### Author: ![Walker\_Blackwell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/walker_blackwell/32/119568_2.png) [@Walker\_Blackwell](https://meta.discourse.org/u/Walker_Blackwell)
#### Post date: [2017年六月17日 22:32 UTC](https://meta.discourse.org/t/redirect-vbulletin-urls-to-discourse-urls/47394/5 "2017-06-17T22:32:22Z")

</div>

For those who do not have MAP or can’t figure it out, I have figured out the easy (dumb) way to do it for topics at least. This works for VBulletin 4. I have not tested on 5 nor do a really want to deal with VBulletin ever again, so I probably won’t. I think the URL structure is the same though. This is for migrating from VBulletin 4 (hosted on NGINX) to Discourse (also hosted on NGINX).

\*\*\* Note, there are security implications with this process, but if you are new to NGINX (like I am) and just need to get this done and then figure out the fancy way later, this is what I did. In short, it requires you to keep your old vbulletin running for a while \*\*\*\*\*

1. Change your VBulletin URLs to “Advanced Friendly URLs” \>Admin\>Settings\>Options\>Friendly URLS. This will get rid of the argument character “?” in all your urls. All the destination posts will be at “…showthread.php/(the-post-id-number)-blablablabla…” Old urls with google juice will forward to the new urls. Don’t worry.

2. Now import your vbulletin and make sure that you uncomment the permalinks section (as described in this thread).

3. After import, open the vb\_map.csv. You will see post to post (ID to ID) maps like xxxx837 yyyy589. The first is the ID of the VB thread and second is the ID of the Discourse thread.

The VB thread is at [http://myamazinglyoldforum.com/showthread.php/837-](http://myamazinglyoldforum.com/showthread.php/837-) and the new discourse one is at [https://myawesomenewforum.com/t/589](https://myawesomenewforum.com/t/589)

1. You can probably guess what to do now. Just create a rewrite in your site-available file (above your root delineation).

Using the example above:

rewrite /showthread.php/837- [https://myawesomenewforum.com/t/589](https://myawesomenewforum.com/t/589) permanent;

1. The “-” is key in this whole equation so remember to put it in there. A simple txt editor with “find-replace” will convert the map file to nginx rewrite directives.

Nginx seems to be able to handle several thousand rewrites (or several hundred thousand as the case may be). I have seen no performance issues so far.

best,  
Walker

---

<div class="post-metadata">

### Author: ![Walker\_Blackwell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/walker_blackwell/32/119568_2.png) [@Walker\_Blackwell](https://meta.discourse.org/u/Walker_Blackwell)
#### Post date: [2018年一月25日 14:57 UTC](https://meta.discourse.org/t/redirect-vbulletin-urls-to-discourse-urls/47394/6 "2018-01-25T14:57:34Z")

</div>

Just a note on all of this. I did finally get rid of the VB forum (for security reasons).

To redirect the `showthread.php?bla-` to `/showthread.php/bla-` in nginx instead of with VB’s own PHP you do this (above your re-write rule list)

(in my case, the old forum lives at “tech” but you will change this to be whatever folder it lives at)

```
location ~ ^/tech(?:/(.*))?$ {
  rewrite ^/tech/showthread.php /tech/showthread.php/$args permanent;
  rewrite ^/tech/content.php /tech/content.php/$args permanent;
}

```

then all the redirect rules live below here:

`rewrite /showthread.php/837- https://myawesomenewforum.com/t/589 permanent;`

On a further note, it took me FOREVER to figure out how to simply replace a question mark with a forward slash in NGINX. Maybe I’m dumb (no I’m certainly dumb), but the above little snippet works like a charm and I don’t see it widely documented elsewhere.

edit\> Thanks for the formatting.
