0

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

Dekel
  • 60,707
  • 10
  • 101
  • 129
pavneet tiwana
  • 216
  • 1
  • 3
  • 17

1 Answers1

0

To redirect the old url to new location, you can use this

RewriteEngine on


RewriteCond %{THE_REQUEST} /map\.php\?m_id=([^\s&]+) [NC]
RewriteRule ^ /learning-journey/%1? [L,R]

Put this above your internal RewriteRules

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • Hey starkeen, thanks for the help. Can you tell me how i can include the slug which i generate for each map in redirect also. – pavneet tiwana Jun 21 '16 at 17:10
  • Where is the slug in your old url? – Amit Verma Jun 21 '16 at 17:13
  • Starkeen , i am a newbie with this thing, when we create a new page we create a slug to be attached to each page, i got it from this page http://stackoverflow.com/questions/5305879/automatic-clean-and-seo-friendly-url-slugs . It is the same as the stackoverflow url structure. Even if we don't add the slug the url works. But we want to have just one url for google. Can we add something to the file that the complete url shows up with the slug. Like in stackoverflow even if you delete half of the slug they will automatically generate it again. – pavneet tiwana Jun 21 '16 at 17:25
  • Will something like this work that on my page I check if the slug attached to the url doesn't match to the slug generated by my page i redirect to the correct url with the right slug. Or you think there can be a better way to do so – pavneet tiwana Jun 21 '16 at 17:29