Welcome to WebmasterWorld Guest from 3.227.208.153

Forum Moderators: phranque

Message Too Old, No Replies

Checking an Ajax script to see if it's being called directly

     
12:38 am on May 5, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Mar 15, 2013
posts: 1203
votes: 119


Looking through the Console, I recently noticed that a menu I created to use via Ajax is showing up in Google results. Which is VERY weird and unexpected!

The Ajax query looks like this:

<script>
$('#foo').ajax('/path/to/example.php');
</script>


Can you guys suggest a way, in either Javascript, PHP, or through the htaccess, to redirect the Ajax script to the homepage if it's called from outside of the Ajax query?

Since I use several scripts like this, an htaccess solution would probably be best, but I'm open to anything.
2:53 pm on May 5, 2018 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:May 1, 2018
posts:104
votes: 17


You could look into disallowing these Ajax scripts with your robots.txt or adding a noindex meta tag or header.

To redirect traffic that is not called via ajax, look for the header $_SERVER['HTTP_X_REQUESTED_WITH']