Download the home page if the user visits the page intended for ajax request?

I use jQuery for a simple website and have the main page 'index.html' which can load some content (e.g. 'info1.html' or 'info2.html') via ajax jQuery queries and display the result of these queries inside the element on the page "index.html".

If the user somehow visits, say, "info1.html" directly, is there a way to redirect or load the main page "index.html"? (or what works best for this type of thing), since Google indexes all the small html files used for ajax requests, and sometimes the user can click on the site through these pages.

Thank.

+3
source share
4 answers

Workaround 1:
since jquery will select the content inside the body tag by default, you can add a head a script to the element to redirect you to the main page or meta tag (or rather), as Daniel mentioned.

Workaround 2:
if your ajaxed files are in a folder, you can use the robots.txt file and google direct to not index the pages in these folders.

or you can do it directly from within these pages (see http://en.wikipedia.org/wiki/Noindex )

+5
source

You can use the meta refresh tag:

<html>
<head>
    <meta http-equiv="refresh" content="0; url=http://mydomain.com/main.html">
</head>
<body>
    <div>
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed 
        ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad 
        eleifend option congue nihil imperdiet doming id quod mazim.</p>
    </div>
</body>
</html>
+3
source

info1.html info2.html. :

$.ajax({
                type: "POST",
                url: "info1.html",
                data:myParameter=1,
                success: function(html){
                    .........
                }
            });

info1.html , myParameter 1. , . , javascript. , info1.html URL-, . , PHP. , info1.php info2.php

+1

, :

XML, HTML.

html, , window.onload java script :

window.onload = function() {window.location.href = 'http://www.google.com';}  
0
source

Source: https://habr.com/ru/post/1737621/


All Articles