Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
889 views
in Technique[技术] by (71.8m points)

php - How to identify if referrer is a 301 redirect

I'm implementing a slug system for my website at the moment. I plan to redirect invalid slugs to the correct on that is stored in the database. E.g.

http://example.com/11/wrong-slug

Hit db, check if 11's slug is wrong-slug if not do 301 redirect

http://example.com/11/right-slug

Detect 301 and inform user that they followed an invalid link

Is it possible to identify the 301 redirect preferably using PHP so I can ask the user to update there bookmark etc.

Thanks, Jamie.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Alternatively you could append a GET parameter to your url (if you don't mind that), and check for it in your PHP script. Something like:

http://example.com/11/right-slug?corrected-from=http://example.com/11/wrong-slug

On the same note you can use the session or cookies, but you must take care to remove them after detection.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...