PHP code to determine if a user was 301 redirected to my site

Is it possible in PHP to know if a user has been 301 redirected to my website?

So in <strong>myoldsite.com</strong> I have a 301 redirect in the .htaccess file to <strong>mynewsite.com</strong>.

Can I place some PHP code in <strong>mynewsite.com</strong> to recognise when a user has been 301 redirected? I just need this to display a specific message if this is the case.

Many thanks for any pointers here :-)


I believe with 301-redirects the HTTP_REFERER field will contain the original referer:

    <li>User enters oldsite.com in address bar and 301 redirected to newsite.com
      <li>referer = ""</li> </ul></li> <li>User is visiting 3rdparty.com, clicks a link pointing to oldsite.com and 301 redirected to newsite.com
        <li>referer = "3rdparty.com"</li> </ul></li> </ul>

        This behavior somewhat makes sense for 301 redirects.

        Solution: I think you should add a query-string parameter to your 301 response such as ref=oldsite and check its value on your new website.

        If you are concerned about having query string parameters in your URLs, you can tell search engines to ignore specific query string parameters. The procedure varies with search engines. Apparently there is a trick that works across all major search engines: the <link rel="canonical"> tag. Examples:

            <li>http://newsite.com/</li> </ul></li> <li>http://newsite.com/?ref=oldsite&page=main and</li> <li>http://newsite.com/?page=main&ref=oldsite
              <li>http://newsite.com/?page=main</li> </ul></li> </ul>


  • Missing Content-Length header when using Nginx + Gzip + Unicorn
  • search text only using Java
  • How to use Google public API access key in android application?
  • ServiceStack: Handler for request not found?
  • Mod_rewrite: Include query string when redirecting
  • google maps api works at localhost but doesn't work at web server
  • How to get the input from a text box on a webpage form
  • I want to bind the click event to the li elements in the xpages type-ahead
  • ManageIQ docker container cannot not be connected with web browser
  • need to identify dynamic input/textareas when inserting to database
  • How to dynamically generate javascript using ScriptSharp?
  • Django login form in bootstrap popup
  • jquery pie chart with drilldown/clickable pie parts
  • Eclipse RCP - Stacking a view with the editor area?
  • Working example of paypal Website Payments Pro Hosted Solution Iframe?
  • How to prompt user that edits have been made upon changing pages or sorting in Kendo Grid
  • How to run requests.get asynchronously in Python 3 using asyncio?
  • JQM (jQueryMobile) Problem with AJAX content and focus()
  • System call time out?
  • Obtain actual browser URL in PHP
  • Entity Framework ObjectContext: Concurrency
  • Angular page doesn't refresh after data is added or removed
  • Using MouseListener to select a range of cells in a grid
  • Dart - Isolate Cross Window Communication
  • Who propagate bugfixes across branches (corporate development)?
  • xcode don't localize specific strings
  • Meteor: Do Something On Email Verification Confirmation
  • Cannot resolve symbol 'MyApi'
  • ilmerge with a PFX file
  • How to get address from latitude and longitude android google map v2 [duplicate]
  • Retrieving value from sql ExecuteScalar()
  • KeystoneJS: Relationships in Admin UI not updating
  • using HTMLImports.whenReady not working in chrome
  • Hits per day in Google Big Query
  • Authorize attributes not working in MVC 4
  • Checking variable from a different class in C#
  • Busy indicator not showing up in wpf window [duplicate]
  • Running Map reduces the dimensions of the matrices
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF