Redirect PHP URL with parameters

370 views Asked by At

I have a website with several URLs like these:

domain.com/aff_link.php?id=363

and I need to redirect all of them to a subfolder called "old"

like this:

domain.com/old/aff_link.php?id=363

those numbers at the end go from 2 up to 4 digits.

How can I do this in htaccess?

Currently I have this code

RewriteCond %{QUERY_STRING} (^|&)(id)=[^&]+ [NC]
RewriteRule ^(/.*)?$ http://domain.com/old? [R=301,L,NC]

but that redirects everthing to domain.com/old/ so as you can see I do not know what I am doing, please help. Thank you in advance.

1

There are 1 answers

2
user2182349 On BEST ANSWER

This should be pretty close ...

RewriteEngine On
RewriteRule (aff_link.php) old/$1 [L,QSA,R=301]

Watch out for leading slashes depending on whether this is in a VirtualHost or Directory or .htaccess block.