php - Routing with Apache mod_rewrite linked files do not work -
i have (and works): using php on apache, have set htaccess route generic friendly/urls/with/slashes index.php. here's htaccess code:
rewriteengine on # redirect trailing slashes... rewriterule ^(.*)/$ /$1 [l,r=301] rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^ index.php [qsa,l] for testing purposes, index.php file contains simple html, link javascript file exist @ proper path:
<!doctype html> <html> <head> <title>a test page goes here</title> <script src="foo.js" type="text/javascript"></script> </head> <body></body> </html> the foo.js file i'm calling has simplest diagnostic inside it:
console.log('howdy'); when try accessing page using proper url, no call redirect, works great. this:
http://myhost/index.php when try accessing page using 1 url parameter, this:
http://myhost/home everything still works expected. page appears, javascript link works.
but when try accessing page using more url pieces, this:
http://myhost/pages/home i 2 errors, this:
uncaught syntaxerror: unexpected token < resource interpreted script transferred mime type text/html: "http://myhost/home/foo.js". and when use browser's development tools @ js code that's causing error, here's contents of js file said be: same html index.php file returning. (so, no wonder there's javascript errors being generated.)
so, tells me is, call html code foo.js being redirected, , contents of index.php being returned instead of contents of foo.js. happens when have multiple elements in url.
btw, it's not js isn't working ... links css files run same problem (they returned html index.php). seems linking , returning file, rather type of file is.
so ... i'm stumped. there trick htaccess need using, i'm not? ideas anyone?
change html following:
<!doctype html> <html> <head> <title>a test page goes here</title> <script src="/foo.js" type="text/javascript"></script> </head> <body></body> </html>
Comments
Post a Comment