J
J
Jedi2017-08-04 22:16:13
PHP
Jedi, 2017-08-04 22:16:13

How to set index folder via .htaccess?

Hello. Here on Open Server there is a domains tab, where you can set an index folder, for example, the "public" folder.
Not all hostings have the ability to set an index folder :(, how can this be done using .htaccess?
How will this all affect performance?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alexey Shashenkov, 2019-03-15
@ignat07

Here's how to send requests one by one using promises one by one

var promise = Promise.resolve();
var result = []
for(let i =0; i< 3;i++){
promise = promise.then(()=> $.ajax(
        {
            url: urlToCreated + '/' + id,
            type: 'GET',
            dataType: 'json',
            data: {skip: skip, limit: 100000},
        }
    ).promise().then(function (data) {
  result.push(data)
    }))
}

I
Ihor Bratukh, 2019-03-15
@BRAGA96

Here is a good es5 example, without Promise and async/await if that matters to you:

var result = {};

deferredParallel([1, 2, 3, 4, 5], function (id) {
    return $.ajax({
        url: urlToCreated + '/' + id,
        method: 'GET',
        dataType: 'json',
        data: {
            skip: skip,
            limit: 100000
        },
        success: function (data) {
            result[id] = data;
        }
    });
}).done(function () {
    console.log(result);
});

function deferredParallel(items, callback) {
    var deferreds = [];
    for (var i = 0; i < items.length; i++) {
        var deferred = callback(items[i], i, items);
        if (typeof deferred === 'object' && deferred.done && deferred.fail) {
            deferreds.push(deferred);
        }
    }
    return $.when.apply(null, deferreds);
}

And here is a working example that you can run in the console, for example, even here on the toaster:
var result = [];

deferredParallel([1, 2, 3, 4, 5], function (item) {
    return $.ajax({
        url: 'https://jsonplaceholder.typicode.com/posts/' + item,
        method: 'GET',
        dataType: 'json',
        success: function (data) {
            result.push(data);
        }
    });
}).done(function () {
    console.log(result);
});

function deferredParallel(items, callback) {
    var deferreds = [];
    for (var i = 0; i < items.length; i++) {
        var deferred = callback(items[i], i, items);
        if (typeof deferred === 'object' && deferred.done && deferred.fail) {
            deferreds.push(deferred);
        }
    }
    return $.when.apply(null, deferreds);
}

The example above made requests in parallel, in network it looks like this :
▮▮▮▮
▮▮▮▮
▮▮▮▮ □□□□□□
READY □□□□□□▮▮▮ □□□□□□□□□□□□□□□
var result = [];

deferredQueue([1, 2, 3, 4, 5], function (item) {
    return $.ajax({
        url: 'https://jsonplaceholder.typicode.com/posts/' + item,
        method: 'GET',
        dataType: 'json',
        success: function (data) {
            result.push(data);
        }
    });
}).done(function () {
    console.log(result);
});

function deferredQueue(items, callback) {
    var ready = $.Deferred();
    ;(function fire (i) {
        var deferred = callback(items[i], i, items);
        if (typeof deferred === 'object' && deferred.done && deferred.fail) {
            deferred.done(function () {
                items[i + 1] ? fire(++i) : ready.resolve();
            });
        }
    }(0));
    return ready;
}

A
Alex, 2019-03-15
@Kozack

In your case, you need to use an async/await statement in a loop; So each next request will wait for the completion of the previous one.

A
Andrey Sanych, 2017-08-04
@PHPjedi

https://toster.ru/answer?answer_id=1062157#answers...

S
Stalker_RED, 2017-08-04
@Stalker_RED

.htaccess files can be scattered across any folder. They will work in the order in which they meet.
For example, when requesting example.com/shop/toys/cars
, Apache will check if there is .htaccess in the /shop folder, then if it is in /shop/toys and so on. Unless, of course, the first encountered htaccess does not interrupt this chain with some rule.
In this case, .htaccess files that are in some other folders will not be used. That is, if you have some /public/.htaccess but the request is not directed to the /public folder, it will not be used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question