Redirecting specific urls to subfolder on same domain
I have moved my phpBB board from dommain.com to domain.com/forum. I have launched a Wordpress website on domain.com.
As a consequence, all links to topics on my board end up on a 404 page of my Wordpress website on domain.com
I would like to redirect links to topics on my board.
/forum should be added.
Is changing the
.htaccess file of my WordPress website the best way to do this? And if so, what would be the correct code?
Of are there better ways (faster/better for SEO) that I don't know of.
Is changing the htaccess file of my Wordpress website the best way to do this?
Implementing this in the root
.htaccessfile is a reasonable way to do this, unless you have access to the main server config. Alternatively, you could perform this redirect in PHP (in WordPress), but that puts the burden on your WordPress site.
For example, at the top of your root
.htaccessfile, before the existing WordPress directives (ie. before
# BEGIN WordPress) try the following:
# Redirect old forum topics to "/forum" subdirectory RewriteRule ^viewtopic\.php$ /forum/$0 [R=301,L]
Any query string is passed through by default. So, a request for
/viewtopic.php?<something>is redirected to
$0backreference contains the URL-path matched by the entire
RewriteRulepattern. ie. "viewtopic.php" (this simply saves repetition).
NB: You should test first with a 302 (temporary) redirect to avoid potential caching issues.