0

I have a website that used to use php "standard" addresses, such as index.php?id=10. Now I've configured mod_rewrite to have better URLs, therefore i added the rule

RewriteRule ^/([0-9]+)/?$ /index.php?id=$1 [QSA]

Consequently, every time someone surfs to /10 he or she will be redirect to index.php?id=10.

As the redirect is identical to the old address, Google continues to give as results the old php-style URLs, and some results are now duplicated when you perform a search in Google.

I subscribed to Google Webmaster Tools and added a sitemap for the website, leaving only the rewrite-style addresses, but after more than two months the old URLs still appear. Is there a way to remove them from Google?

Thanks a lot!

1 Answers1

0

Redirect incoming old-style URLs to a site returning 404 and google will remove them. Incoming new link's wont be affected as long as you stay with interal rewrites (and exclude the resulkts from being rewritten again, either by having the rule after the others ur uisng the L flag).

This could look like this (untested, but you should at least get the idea):

RewriteRule ^/([0-9]+)/?$ /index.php?id=$1 [QSA,L]
RewriteRule ^/index.php?id=([0-9])$ - [R=404,L]

Sending the permanent redirect status code 301 (plus location header) to redirect to the new URLs should also work, in that case google won't remnove the entries but correct the URL.

RewriteRule ^/([0-9]+)/?$ /index.php?id=$1 [QSA,L]
RewriteRule ^/index.php?id=([0-9])$ /$1 [R=301,L]

You should, however, keep the old style URLs functional anyway, because Cool URIs don't change.

Johannes H.
  • 5,875
  • 1
  • 20
  • 40
  • How can I redirecth them? Apache is transforming them into the `php`-style. Can I do it directly using another rewrite rule? – Alessio Palmero Aprosio Feb 18 '14 at 16:55
  • Exactly. Redirects are done internally (unless you specify otherwise using the R flag or a FQDN), so the browser never sees the URL that you rewrite the request to. Because of this, it will never request the old stlye URLs, unless some user (or bot) directly requests them. It's therefore safe to just redirect the old URLs. I'll edit a few suggestions to my answer, give me a sec. – Johannes H. Feb 18 '14 at 16:57