3

I moved from IPSuite forums system to Woltlab burning board forum system. What happen next was that my old links that start with:

example.com/index.php?/topic/

Now start with:

example.com/forum/index.php?thread/

in my new site.

So, when someone clicks on my Facebook posts he get the old address instead of the new one, and he gets an 404 error page.

I want to make all my incoming links from google facebook and so, to convert themselves into my new address (example.com/forum/index.php?thread/) so I will not have to change them one by one. I know it is something related to implement certain code via .htaccess file but I'm not sure what is it. I also saw that but didn't got it since it is another case.

1

You state that the URLs only "start with" the prefix mentioned, so I assume the "slug" or "forum ID"(?) that follows this prefix is the same on both the old and new sites.

So, you have an old URL of the form:

example.com/index.php?/topic/<something-here>

that should redirect to:

example.com/forum/index.php?thread/<something-here>

Since you need to read from the query string portion of the URL, you will need to use mod_rewrite (as opposed to a simple mod_alias Redirect).

This should go near the top of the .htaccess file in the document root of your site. The order of these directives could be important if you have existing directives in your file.

For example, try something like the following:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^/topic/(.*)
RewriteRule ^index\.php$ /forum/index.php?thread/%1 [R=302,L]

The %1 in the RewriteRule substitution is a backreference to the captured group, ie. (.*) in the preceding CondPattern. Note that this is currently unrestrictive, since you've not stated what the remainder of your URLs consist of. However, it is better to be as restrictive as possible. For example, if the remainder of your URLs consist of just the characters a to z and hyphens and are always longer than 10 characters then change that pattern to read: ^/topic/([a-z-]{10,})

Note that this is a temporary (302) redirect. Once you are sure this is working OK then you'll probably want to change this to a permanent (301) redirect. ie. Change R=302 to R=301 in the RewriteRule flags. 301s are cached hard by the browser, so can make testing problematic, unless you first disable all caching.

Just some additional notes:

  • Are you sure you want to keep index.php in the URL? (Although this isn't necessarily just a case of changing this rule in .htaccess - you will also need to change the URLs in your application.)
  • This type of URL structure makes having URL parameters very awkward. (Not sure how/if this would be supported by your forum software?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.