On our website we rewrote old url's which had the following structure of
\map.php?m_id=(a map no.)
to the following structure
/learning-journey/(map no.)/(query slug)
The query slug is page specific, for example, example.org/learning-journey/567/getting-started-with-git-version-control-system
We have used the following code for implementing the new URL's
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^learning-journey/([0-9]+)/?([0-9a-zA-Z-]+)?/?$ map.php?m_id=$1 [NC] # deals with maps
RewriteRule ^learning-journey/?([0-9]+)?/css/(.*)$ /css/$2 [NC]
RewriteRule ^learning-journey/?([0-9]+)?/js/(.*)$ /js/$2 [NC]
RewriteRule ^learning-journey/?([0-9]+)?/img/(.*)$ /img/$2 [NC]
RewriteRule ^learning-journey/?([0-9]+)?/user_images/(.*)$ /user_images/$2 [NC]
RewriteRule ^learning-journey/?([0-9]+)?/(.*)$ /$2 [NC]
The problem is that the old URL's still exist and are being indexed by google.
How can we make sure that the old URL's redirect to the new URL's without creating an infinite loop. We want to implement a 301 redirect