1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.0 How to redirect vb #post3324 to xf #postid-1234

Discussion in 'XenForo Questions and Support' started by Marcus, Oct 13, 2011.

  1. Marcus

    Marcus Well-Known Member

    How can I redirect a vb thread showthread.php?t=73139#post3324 to threads/234/#postid-1234 ? It does not work currently. Thanks.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Did you import from vBulletin? If so then you can use these redirect scripts:

    http://xenforo.com/community/threads/redirection-scripts-for-vbulletin-3-x.5030/

    If you only want to redirect one specific URL then you can use this code in a .htaccess file (only works on Apache servers):

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/showthread\.php$
    RewriteCond %{QUERY_STRING} ^t=73139$
    RewriteRule ^ http://www.yoursite.com/threads/234/? [R=301,L]
    
    That will perform the desired redirect for that specific thread, minus the anchors which can't be manipulated by the server.
     
  3. Marcus

    Marcus Well-Known Member

    Hi Jake, thanks! I have imported from vb and the redirection script works for threads alone. But once I have a redirection to a special post within a thread, the redirection script
    - does not direct me to the right page
    - and therefore does not direct me to the right post.

    This is a sample URL:
    showthread.php?t=123&page=3#post546878
    -> anchor redirection is possible with jquery for the anchor

    Sometimes vb4 writes the same topic like this:
    showthread.php?t=123&page=3&postid=546878#post546878
    -> anchor redirection is possible with jquery for the anchor
    -> anchor redirection is also possible also with &postid
     
  4. Mike

    Mike XenForo Developer Staff Member

    You can't redirect (on the server side) based on an anchor, as it's not sent to the server. You'd have to do some custom JS to do that.
     
  5. Marcus

    Marcus Well-Known Member

    Hi Mike, this is exactly what I said. I have some questions regarding the redirector:

    - page=x are not redirected, is that a bug?
    - if there is a &postid=x in the url, should this be redirected to the right page with the anchor #post-y?

    By the way, I manipulate my page depending on the anchors with jquery actually.
     
  6. Mike

    Mike XenForo Developer Staff Member

    It doesn't try to keep the specific page as it stands. And I don't think "postid" is normally in URLs like that - is that a vB4 thing? (We have redirects for "p".)
     
  7. Marcus

    Marcus Well-Known Member

    So onces I migrate to xenforo from vb all my thread page urls are not taken care of?
    And the post-anchors are also not taken care of, right?
    My users very often link within threads to other posts within the same thread, this information would all be lost?

    This is not only huge for my members but also for SEO as my site structure is also built on the various inline-linking which all now would permanently redirect to a different content.
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    "postid" was a vB2 thing. vB3 and vB4 use "p" by default but they also recognize "postid" (probably to maintain compatibility with old links). It's the same for "threadid" and "t".

    As I said, the server can't manipulate anchors. The server can't see the anchor because it is not sent as part of the request. Here is a demonstration of this that I found a while ago:

    http://delorie.com:81/type-whatever-on-your-mind-here#and-here-too
     
  9. Marcus

    Marcus Well-Known Member

    I don't understand why not even the right page is served when the page is given in the url, or when xf looks up a post and delivers a thread, then the thread should be served with the right page. Is there even a old_id | post table stored after the import? If yes, you could use this. The current implementation of the 301 redirector is rather basic. It should not be hard for any xf addon dev to fetch the anchor with jquery and then redirect to the right page.
     
  10. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    The page numbers don't necessarily match up. The number of posts per page might be different. So if the URL provides a threadid and page number then XenForo can only redirect to the threadid. I just tested and confirmed this:

    original: showthread.php?t=9710&page=2
    redirect: index.php?threads/thread-title.9013/

    I suppose the redirect script could check the number of posts per page and then specify the page only if that number is the same. That would require the importer to record the number of posts per page in the import log.

    As for the postids... if a postid is given in the URL then it is redirected to the correct page with an anchor. I just tested this myself. For example:

    original: showpost.php?p=118757
    redirect: index.php?threads/thread-title.9013/page-2#post-116535

    original: showthread.php?p=118757#post118757
    redirect: index.php?threads/thread-title.9013/page-2#post-116535

    When the URL contains a postid you can make a correct redirect like this. But the postid must be part of the query string. If the postid is only specified as an anchor then the server won't see it. As Mike suggested, this may be possible with javascript.
     
    Marcus likes this.
  11. Marcus

    Marcus Well-Known Member

    Thanks very much for your very helpful post. I have the same posts/page setup in both my forums, how else would the pages match :D I have missed the outstanding ?p redirection, this is excellent integration from xenforo!

    Once there is an integration for pages, too I am migrating to xf. But without that, I'd very much have my IDs stay the same after the migration so that none of these anchor issues are even there.
     
  12. Marcus

    Marcus Well-Known Member

  13. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Maybe. Updating forum links after an import requires mapping the old ids to the new ones, and that find / replace tool doesn't do that. It is useful for updating BB codes and updating links to point to a different directory if you move your forum, but it doesn't do any id mapping like the redirect scripts do.

    Here are some specific examples of how that addon can be used:

    http://xenforo.com/community/threads/phpbb-import.17942/#post-233165
    http://xenforo.com/community/threads/removing-mybb-tags-after-importing-database.19558/#post-251195
     
  14. Marcus

    Marcus Well-Known Member

    From a short view over Kiers script, in PostReplace.php you can easy configure public function actionReplace() to query through each found old_id and replace it with the current new_id. Pretty easy but powerful stuff.
     
  15. Marcus

    Marcus Well-Known Member

    This is a quick and easy help to just use Kiers importer to greatly improve your internal links:

    Replace this
    showthread.php?t={1}#post{2}
    to this
    showthread.php?t={1}&p={2}#post{2}
     
  16. Marcus

    Marcus Well-Known Member

  17. Robert9

    Robert9 Active Member

    There is a problem with links from vb without a threadid.
    I have only showthread.php?p=12345

    Now i have no idea how to replace (or rewrite) it.
    Can xenforo call a thread only with the postid, please?
     
  18. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    These scripts handle those types of URLs:

    https://xenforo.com/community/resources/redirection-scripts-for-vbulletin-3-x.264/

    It will redirect to the associated thread in XenForo and anchor to the page / position of that postid.
     
  19. Robert9

    Robert9 Active Member

    So xf can come to a threadid only with the postid?
    Then i will watch it later and hope to find an url that i can use for regex in the posts itself.
     
  20. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yes.
     

Share This Page