Skip to:
Content
Pages
Categories
Search
Top
Bottom

Rewriting URLs

  • I switched from phpBB to bbPress recently thanks very much in part to a script found in these forums.

    Now, many of the existing posts contain links to each other in the old phpBB format /topic.php?t=123. Since the topic IDs have stayed the same in the conversion process, I’d like to use ModRewrite to automatically redirect to the new /topic/123 URL scheme. I’ve tried the following in my .htaccess, but it doesn’t appear to work. (Admittedly, my knowledge of ModRewrite is shaky at best.)

    RewriteEngine on
    RewriteRule ^/forums/viewtopic.php?t=([0-9]+)$
    /forums/topic/$1 [R]

    (In the real code there isn’t a linebreak on the second line.)

    Does anyone have any advice?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Marky,

    I have the same issue. I want to switch from PHPBB to bbPress and keep the internal links the same. You can try to adjust my plugin for this:

    https://bbpress.org/forums/topic/771

    Depending on how the links are right now at PHPBB you may be able to do it.


    Sam Bauers
    Participant

    @sambauers

    Try:

    RewriteRule ^/forums/viewtopic.php?t=([0-9]+)$

    /forums/topic/$1 [R]

    Escaping the dot and the dollar-sign. You might also need to specify:

    RewriteBase /directory/path/where/forum/resides/

    Just after “RewriteEngine on”

    I do not think that the rewrite rule alone will do it. You also need to change the way the links are generated by bbPress.


    Sam Bauers
    Participant

    @sambauers

    Escaping the dot and the dollar-sign

    I meant, “Escaping the dot and the question-mark”


    Sam Bauers
    Participant

    @sambauers

    > I do not think that the rewrite rule alone will do it. You also need to change the way the links are generated by bbPress.

    Not if all he wants to do is redirect links inside his posts to the right topic. If he wanted to make all his links look like that within his installation there is definitely more he would have to do.

    Yes, that’s what I was thinking of.

    Sam, did you finished your permalinks script. I am stuck with mine because I do not know how to create the mod_rewrite rules for this kind of page:

    http://www.dfur.com/designer_furniture/topic5

    see page 2

    http://www.dfur.com/designer_furniture/topic5/page/2

    My mod rewrite is throwing me back to the main cat.

    Well, I’m still having trouble getting this working. Indeed, all I’d like to do is redirect existing links to the new topics; I don’t want to change the permalink structure or anything else.

    I’ve tried escaping the dot and question mark, but it’s still not rewriting the URL. I’m wondering, at this point, if ModRewrite can handle urls with parameters in them. I’ve tried some other quick tests (RewriteRule ^/forums/blah.foo$ /forums/topic/1/) and it worked no problem, so ModRewrite isn’t the problem itself.

    Any other suggestions?

    Well, I’ve found the solution! Apparently, ModRewrite doesn’t count the query string as part of the URL, so it needs to be addressed separately. These rules did the trick:

    RewriteEngine On
    RewriteBase /forums/
    RewriteCond %{QUERY_STRING} ^t=([0-9]+)$
    RewriteRule ^viewtopic.php$ /forums/topic/%1 [R,L]

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.