如何捕获指向不存在的页面/文件的URL? [关闭]

How to capture URL that points to non-existent page/file?

Lets say users enters a url like www.myserver.com/randomString, I would like to redirect the page to index.php, but also capture the "randomString"? I'm aware .htaccess can do the redirect on file not found, but what abotu the URL capture?

Simple method:

Use $_SERVER['HTTP_REFERER'] to find out previous address. It cannot be fully trusted since it can be manipulated by some agents.

More complicated method:

You may use router-like, let's say, index.php on DocumentRoot and hide it from URL. To elaborate, all the requests will pass from index.php. In your example, it will become www.myserver.com/index.php/randomString and with .htaccess you may hide index.php which will eventually become www.myserver.com/randomString.

Then you may capture whatever you want just analyzing index.php

If it is just for tracking you can use Google Webmaster Tools