PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 8, 2022

[FIXED] Redirecting specific urls to subfolder on same domain

 February 08, 2022     .htaccess, apache, wordpress     No comments   

Issue

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.

For example:

Redirect: example.com/viewtopic.php?f=17&t=35

To: example.com/forum/viewtopic.php?f=17&t=35

So only /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.


Solution

Is changing the htaccess file of my Wordpress website the best way to do this?

Implementing this in the root .htaccess file 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 .htaccess file, 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 /forum/viewtopic.php?<something>.

The $0 backreference contains the URL-path matched by the entire RewriteRule pattern. ie. "viewtopic.php" (this simply saves repetition).

NB: You should test first with a 302 (temporary) redirect to avoid potential caching issues.



Answered By - MrWhite
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing