Some help doing 301 redirection within htaccess

I'm migrating an old site from custom php to wordpress and I'm stuck doing some redirection expression in the new site.
I would really appreciate some help.

I would need to go from

I've done many other redirection for pages and categories so I know that my htaccess is working, the problem must be in the expression
This what I got so far
To be honest I don't really know how to use a 2 level folder in my RewriteRule

RewriteEngine on
RewriteCond %{QUERY_STRING} aid=3
RewriteRule ^/lang/es/artist\.php$ [L,R=301]

Thanks for your time

  • Kasia Swiderska
    • Support nomad

    Hello BKBAI,

    Please try this code:

    RewriteEngine On
    RewriteCond %{REQUEST_URI}  ^/lang/es/artist.php$
    RewriteCond %{QUERY_STRING} ^aid=3$
    RewriteRule ^lang/es/artist.php(.*)$ /artistas/artistname3/? [R=301,L]
    RewriteCond %{QUERY_STRING} ^aid=4$
    RewriteRule ^lang/es/artist.php(.*)$ /artistas/artistname4/? [R=301,L]

    You will add you add a RewriteCond & Rule for each one. So in case of above, if url contains aid=3 it will match with the rule below for artistname3

    kind regards,

    • The Incredible Code Injector

    Thanks Kasia,
    This seems to be a better approach than what I was trying. Unfortunately it's not working at all.
    No redirection is performed, there is no change in the url.
    Did you tried it on your side?

  • Rupok
    • Support Ninja

    Hi BKBAI,

    What you tried is almost right. Just you added a slash (/) which should not be there. So the code you should be using is:

    RewriteCond %{QUERY_STRING} aid=3
    RewriteRule ^lang/es/artist\.php$ /artistas/artistname/? [L,R=301]
    RewriteCond %{QUERY_STRING} id=2
    RewriteRule ^lang/es/artist\.php$ /artistas/artistname/? [L,R=301]

    Please note, as your .htaccess file should be containing the following line:
    RewriteEngine On
    and as you will be adding your custom rules at the bottom of the file, so you don't need to add this line again.

    I've checked the code I just provided and it's working in my test site.

    Please let us know if you have any confusion or if this doesn't work for you. We will be glad to help further.

    Have a nice day. Cheers!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.