Home » Php » javascript – .htaccess RewriteRule blocked/ignored for .css and .js extension?

javascript – .htaccess RewriteRule blocked/ignored for .css and .js extension?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have switched servers and suddenly some of my .htaccess rules stopped working. One of them is the one bellow which redirects /scripts.js to my /includes/load_js.php file.

# NOT WORKING
RewriteCond %{REQUEST_URI} scripts.js
RewriteRule . includes/load_js.php [L]

The strange part is that, if (for testing purposes only) I rename the rule from scripts.js into, lets say scripts.tst then is working, I can change the extension into anything except .js or .css and is working, otherwise for .js and .css I get 404 Not Found.

# WORKING BUT NOT NEEDED, I NEED .JS
RewriteCond %{REQUEST_URI} scripts.tst
RewriteRule . includes/load_js.php [L]

Any help is much appreciated!
Thank you!

How to&Answers:

It looks like the server was running both Nginx and Apache and there was some sort of conflict in serving files. While Apache using my .htaccess file was successfully honoring some of the redirects, others, on the other hand were “stolen” by NGINX (*.jpg, *.png, *.js, *.css) and this way the request never had the chance to even reach my .htaccess to process the redirect rules.

TL;DR: Server configuration: both Apache and NGINX == NO-NO, results in fighting over requests, nobody wins.

“SOLUTION” <- (notice the quotes): The WebMaster removed NGINX and only Apache remained standing, this way, processing my .htaccess and all rules working like on the previous server.