htaccess: upload a directory only to a url series

52 views Asked by At

Anyone know how to redirect with .htaccess all the URLs of the form:

  • www.example.com/showthread.php(any content) to
  • www.example.com/forum/showthread.php(same content)

I just want it to happen in this type of URL, there are other URL that I do not want to be modified.

1

There are 1 answers

0
MrWhite On BEST ANSWER

I assume (any content) is referring to a query string (starting with a ?). You can do something like the following using mod_rewrite in your root .htaccess file.

RewriteEngine On
RewriteRule ^showthread\.php$ /forum/$0 [R=302,L]

This would need to go near the top of the .htaccess file.

This will redirect a URL of the form /showthread.php?<something> to /forum/showthread.php?<something>.

$0 is a backreference to the entire URL-path that is matched. The query string is automatically copied through to the target URL.

This is a 302 (temporary) redirect. Change to a 301 if this intended to be permanent - but only after you have confirmed it's working OK.