XF 2.0 Redirecting existing link to the new forum

taydin

Member
I have migrated to XenForo a few days ago, and then I went ahead and corrected all links in other sites that are pointing to the forum (the forum is new, there aren't a lot of links). But there is this one forum where I cannot edit the message anymore. There is a link that pointed to the correct topic in the old forum (SMF):

Code:
http://mekatronik.org/forum/index.php/topic,4.0.html


Because I cannot edit that message anymore (forum policy I think grrrr), I want this link to redirect to the correct topic in the new forum, which is:

Code:
http://mekatronik.org/forum/threads/duesuek-degerli-direncler-hassas-bir-sekilde-nasil-oelcueluer.4/


Is there a way to do this, without requiring PHP expertise? I know my way around the linux shell, C/C++ programming, and light web work (html, jquery, css), but I don't know anything about PHP.
 
Given that it looks like the IDs are the same, you can likely do this via your web server. If it's Apache, mod_rewrite would do what you want.

As a little bit of a guideline, you can check out this thread. However, note that the URLs aren't exactly the same as what you're showing, so the exact rules would differ:

 
Ok, here is what I've tried:

I have opened the main .htaccess file under the forum root directory and have made the mod_rewrite block look like this:

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On

    #    If you are having problems with the rewrite rules, remove the "#" from the
    #    line that begins "RewriteBase" below. You will also have to change the path
    #    of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    #    This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # My lines begin
    RewriteCond %{REQUEST_URI} /forum/index\.php/topic
    RewriteRule /forum/index\.php/topic,([0-9]+) /forum/threads/$1
    # My lines end

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]

</IfModule>

But when I open the http://mekatronik.org/forum/index.php/topic,4.0.html link, I'm getting an "Oops! We ran into some problems" page.

By the way, when I open http://mekatronik.org/forum/threads/4, it does take me to the correct topic

What could be the problem?
 
Also, add a L flag after 301:

[R=301,L]

and if your server supports it, add QSD, to discard any parameters which automatically get appended otherwise. For example, if the source URL is:

Code:
http://mekatronik.org/forum/index.php/topic,4.0.html?&param=1

Without QSD your redirect would end up being:
Code:
http://mekatronik.org/forum/threads/$1?&param=1
With QSD your redirect would be:
Code:
http://mekatronik.org/forum/threads/$1

If your setup does not support QSD, then add ? to the end of the redirect URL to discard it.

Also, with a 301 redirect, you should specify the entire URL. Not specifying the entire URL makes it an internal redirect.

Lastly,
Code:
RewriteCond %{REQUEST_URI} /forum/index\.php/topic
Is redudent and not needed, since the REQUEST_URI is specified in the the rewriterule.

The code you should use would be either of the following

Code:
RewriteRule ^forum/index\.php/topic,([0-9]+) http://mekatronik.org/forum/threads/$1 [R=301,L,QSD]

or

RewriteRule ^forum/index\.php/topic,([0-9]+) http://mekatronik.org/forum/threads/$1? [R=301,L]
 
Thanks for the info. Here is how the finally working rule looks like:

Code:
RewriteRule ^index\.php/topic,([0-9]+)\.([0-9]+)\.html$ http://mekatronik.org/forum/threads/$1 [R=301,L,QSD]

It is pretty much exactly what MySiteGuy has written, except the path had to exclude ^forum, which is the forum root directory. I have also added the other part, the 0 as a parameter, it case I needed it for some reason later.

Now armed with this knowledge, I have also gone ahead and did the rewrites for existing google results. It looks like google will take some time to use the new forum paths.

Code:
http://mekatronik.org/forum/index.php?topic=7.0

But apparently if the URL contains query string arguments, just a single RewriteRule isn't enough. I had to add a RewriteCond:

Code:
RewriteCond %{QUERY_STRING} ^topic=([0-9]+)\.([0-9]+)$
RewriteRule ^index\.php$ http://mekatronik.org/forum/threads/%1 [R=301,L,QSD]
 
The last two lines you provided should do the job for the parameters. If you haven't, placed them above the other set, so urls with parameters are processed first.

Just be happy you didn't use the SMF pretty urls addon, most of its urls cannot be redirected solely with .htaccess. I ended having to write PHP code which looked up the url in the SMF pretty urls cache table to find the non-pretty equivalent. And those not in the cache, I had to do a scan of the closest matching thread title in the database, and then redirect that thread's id. It was a hack, but it worked. :)
 
Back
Top Bottom