Search code examples
wordpresspermalinks

Redirect old wordpress URLs articles to new website and new permalinks URLs structure


I am making a new website to replace an existing website. And we are not keeping the previous permalink structure : see below
OLD URL = http www .domain.com/article.php?ID=3242
NEW URL = http www .domain.com/author/post-name

So we want to redirect the old urls to the new ones. How could I do that easily in the htaccess file ?

I tried redirect 301 but does not work.
RedirectMatch 301 ^/article.php?ID=3242 http://www.domain.com/author/post-name


Solution

  • RedirectMatch won't match the query string (the part after the ?). This article explains a bit more, but this should work:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/article\.php$
    RewriteCond %{QUERY_STRING} ^ID=3242$
    RewriteRule ^(.*)$ http://www.domain.com/author/post-name [R=302,L]
    

    Note that I changed it to a 302 redirect while you're testing; I'd only change it to a 301 once you're sure you've got it right (to avoid browsers caching incorrect redirects).