K
K
Kornely2022-01-11 19:21:04
AJAX
Kornely, 2022-01-11 19:21:04

Is it possible to allow viewing only on Ajax page loading?

Let's say page 1 is blocked from viewing via a 301 redirect:

header('Location:/',TRUE,301);
    exit();

But it is necessary that on page 2 , using jquery, page 1 is loaded and viewed .

That is, it was available exclusively within the framework of page 2 . It is not shown in the usual way via ajax due to 301. I tried to set the condition substr_count($_SERVER['REQUEST_URI'], 'pade1') in the redirect - of course, it did not work.

That is, it should be like this:

1. When loading page 1 , it should redirect to the main page (not through JS, because it will be available to search engines).
2. When loading page 2 , page 1 should be visible on it .

Is it possible to do this and how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadim Zakirov, 2022-01-12
@zkrvndm

Do like this:

<?php

// Если мы получили GET-запрос:

if ($_SERVER['REQUEST_METHOD'] == 'GET') {
  
  header('Location:/', TRUE, 301); // Переадресуем на главную
  
}

// Если мы получили POST-запрос:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  
  // Выводишь данные, которые нужны
  
}

When making an Ajax request, simply change the request type from GET to POST.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question