0

Beginner at .htaccess mods and handling pretty URLs.

I have a php/bootstrap/mysql/javascript page: http://localhost/modules/posts/questions_all.php.

I would like to redirect pages like http://localhost/modules/posts/questions_all.php/1234 to the original page.

I have modified the .htaccess file as such.

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^modules/posts/questions_all.php/?$    modules/posts/questions_all.php    [NC,L] 

It seems to redirect to the original page but produces some type of endless javascript loop which appends portions of the code over and over again creating a mess of a page.

In the Chrome console inspector, I get this error which does not occur in the normal load of the page. But with /1234 at the end of the URL, the Error is:

DevTools failed to parse SourceMap: http://localhost/modules/posts/questions_all.php/bootstrap.min.js.map
[Violation] Forced reflow while executing JavaScript took 32ms

The request for the SourceMap did NOT occur with the original page, which functioned perfectly without console errors.

This seems to happen in firefox as well, so I don't think it is a matter of turning off the SourceMap feature in the Chrome Inspector? With the Chrome inspector NOT engaged, I still get this problem.

I have used the same approach for htaccess mods to other similar pages (with bootstrap) for pretty URLs, but I do not get that error and they function fine, but not this page...!

Thank you in advance!

[EDIT]: the found issue is somehow related to an infinite scroll piece of code, but still am not sure why I get an infinite loop. Purpose of code is to continuously load data until the bottom of the screen is reached, then stops. It works fine without the /1234 added to the URL, but when /1234 is added, it seems to go into an infinite loop and causes other parts of the code to execute as well.

The load_data function is an AJAX call to retrieve data.

Code below:

//autoload portion.  when scrolling reaches the bottom of the screen, triggers another load of data
    $(window).scroll(function(){
        if($(window).scrollTop() + $(window).height() > $("#load_data").height() && action == 'inactive'){  
            action = 'active';
            start = start + limit;
            setTimeout(function(){
            load_data(limit, start, search, tag);//recursive loading function
            }, 500);
        }
    });
hder
  • 67
  • 3
  • 11

1 Answers1

0

Seems like the EDIT above was not the problem. Instead, it was the URL reference in the AJAX calling function. Not sure why, but using htaccess as shown, the url had to be complete with http: reference, then it worked fine.

$.ajax({

url:"questions_all_autoscroll_fetchdata.php" - original worked without htaccess mods, but no longer with htaccess mods

url:"/questions_all_autoscroll_fetchdata.php" - still did not work with htaccess mods

url:"http://localhost/modules/posts/questions_all_autoscroll_fetchdata.php" - worked fine with htaccess mods.

...});

If someone can provide an explanation, I would appreciate it. Also, if there is a way to make it work with the relative url, it would be more helpful to know also.

hder
  • 67
  • 3
  • 11