2

I need to redirect:

example.com/wiki/?t=1234 

to

example.com/vb/showthread.php?t=1234

The numbers "1234" is hundreds of pages with different numbers

I try in .htaccess but doesn't work:

RewriteCond %{QUERY_STRING} t=[0-9]
RewriteRule ^(.*)$ /vb/showthread.php?t=$1 [L]
Saadedin
  • 21
  • 2

1 Answers1

1
RewriteCond %{QUERY_STRING} t=[0-9]
RewriteRule ^(.*)$ /vb/showthread.php?t=$1 [L]

This will match the request, but won't redirect as intended ($1 is a backreference to the captured group in the RewriteRule pattern, not the query string). This is also an internal rewrite, not a "redirect" - as stated.

To redirect /wiki/?t=1234 to /vb/showthread.php?t=1234, where 1234 is variable, then you should do something like the following instead:

RewriteCond %{QUERY_STRING} ^t=(\d+)
RewriteRule ^wiki/$ /vb/showthread.php?t=%1 [R=302,L]

This matches the URL-path /wiki/ and a query string that starts t= followed by 1 or more digits. The digits are captured by the regex (\d+).

The %1 backreference (note the %, not $) is a backreference to the captured group in the preceding CondPattern.

Note that this is a 302 (temporary) redirect. But don't change this until you are sure it's working OK.

MrWhite
  • 11,643
  • 4
  • 25
  • 40
  • Great, this one work. RewriteCond %{QUERY_STRING} ^t=(\d+) RewriteRule ^(.*)$ /vb/showthread.php?t=%1 [R=302,L] Thank you so much – Saadedin Feb 09 '19 at 12:28
  • By itself that would create a redirect loop. But I guess you must have other directives that prevent this. – MrWhite Feb 09 '19 at 13:19
  • If this helped answer your question then please mark it as accepted (checkmark below the voting arrows on the left) to remove it from the unanswered question queue. Once you have 15+ rep then you can also upvote answers you find useful. Thanks, much appreciated. :) – MrWhite Feb 09 '19 at 13:20