Search code examples
php.htaccessseohttp-status-code-301

How to detect 301 redirect using php


Possible Duplicate:
How to identify if referrer is a 301 redirect

Using htaccess Im doing a 301 redirect to redirect old urls to the new urls, the issue is the url contains the id that is stored in the db. But I have a new db with new ids so now when the old url redirects to the new url a different record loads on the page. So what I did was store the old ids along with the new ids so I know what old id belongs to the new id. However how can I detect someone is trying to access the old url? Is there a way in php to detect the person coming to the page is being redirected via a 301? I dont want to add anything new to the url due to SEO reasons so I really need to know if I can detect if they came to this page via 301 redirect. Hope this makes sense.


Solution

  • Add another parameter to the redirect like redirect=true, check the param to let your app know it was a redirect, start the session, and then redirect again to the final, unaltered url, compare the session to know, that a user came from the redirected url.

    Or do what Salman says, use a canonical url.