.htaccess treats .js files as php

Go To StackoverFlow.com

0

I've written a very simple MVC FW, so all requests are routed to index file and the index file dispatches requests to the controllers.

I have the following .htaccess:

RewriteEngine On
RewriteBase /SlotDemo
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

And it works great but for some reason it tries to route my .js files as if they were php files (tries to route them to index.php which of course causes error).

What should I add/remove to make it treat '.js' as it treats the css files?

2012-04-03 19:29
by Tomer
RewriteCond %{REQUEST_FILENAME} - - NoName 2012-04-03 19:31
it didn't help : - Tomer 2012-04-03 20:25
sounds like something else is going on here - NoName 2012-04-03 20:31
Just a side note, in case you weren't aware: RewriteBase is only for redefining the URL base, not the filesystem base path - Pierre-Olivier 2012-04-03 20:48
Thanks, i know, since i have a couple of sites on my local computer, this site resides in its own folder and thus i need the RewriteBase - Tomer 2012-04-03 21:04


1

You can easily combine both rules into one like this:

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link
RewriteCond %{REQUEST_FILENAME} !-l
# forward the URI to front controller index.php 
RewriteRule ^ index.php [L]
2012-04-03 19:37
by anubhava
Still no good : - Tomer 2012-04-03 20:28
Is this the only code in your .htaccess here? I suspect you have some other .htaccess in DOCUMENT_ROOT as well - anubhava 2012-04-03 20:30
checked again, only one htaccess file. there is another one that resides in a different local site (i.e. htdocs/another_site/.htaccess) on the same server but I don't suppose it matters? - Tomer 2012-04-03 20:40
Just for the sake of testing change RewriteRule to RewriteRule ^(?!\.js).*$ index.php [L] and see if JS file still passes through to index.php. If yes then there is some other conflicting redirect code somewhere - anubhava 2012-04-03 20:44
tried it and i still get the same error, could it be caching (although i cleared the cache and also restarted the server) - Tomer 2012-04-03 20:51
As you can see clearly that this particular .htaccess is NOT the culprit. You have some other Redirection code somewhere causing this. (it could be some PHP code as well). Caching is not an issue here since its an internal forward. You can enable RewriteLog in httpd.conf and see what are all RewrtieRule firing. That will help you to track this issue better. Good luck - anubhava 2012-04-03 20:55
Got it! I'm so stupid, I forgot to actually put the js files in the directory!!! thank you for all your help - Tomer 2012-04-03 20:58
lol :) that explains.. - anubhava 2012-04-03 20:58


0

CSS and JavaScript files should be treated equally, check your requests for spelling errors or casing differences. (ex: jQuery.js is not the same as jquery.js)

2012-04-03 19:59
by Kristoffer Sall-Storgaard
Double checked the links, all seems fine - Tomer 2012-04-03 20:27
Ads