Reputation: 11
First of all, thanks to anyone who tries to crack their head over this.. I already got 12 stitches.
This is what I have:
mysite.com/documentation - documentation page with menu div and content div (content div will be populated by Ajax when clicking on item in menu div).
mysite.com/documentation/subject-1-content - the actual content page of a menu item in the documentation page. This will be populated into the div by Ajax.
My problem is that if someone goes directly to mysite.com/documentation/subject-1-content , they get to the actual content and not the documentation page with this content populated in the div.
Is it possible at all to redirect a URL to a different URL + to activate an Ajax that calls the content of the first URL + not create an infinite loop of redirections?
Thank you in advance.
Upvotes: 1
Views: 34
Reputation: 12709
If you need to do it on the client side, you can make the content page mysite.com/documentation/subject-1-content redirect automatically to the documentation page possibly with a query param or hash, and the documentation page can read that param and load the required ajax content
Upvotes: 0
Reputation: 1985
If I understand correctly you want to make a redirect if the page is not accessed through an ajax call.
Ajax calls pass a header called HTTP_X_REQUESTED_WITH. I'm assuming you are using PHP as server side so the code to detect the header and redirect in case it is empty (direct call to the page) would be:
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) {
header("Location: mysite.com/documentation");
die;
}
//rest of your code
Upvotes: 0