i know, this looks stupid, but i am a new one in scripting so please help, i want my src not be ending with file with extension. like:
<script src="mysite.com/dir/"></script>
and NOT like this:
<script src="mysite.com/dir/script.js"></script>
is this done with开发者_运维问答 HTACCESS or with what?
P.S. I want to create something like a hitcounter and dont want athers to see my script code
here is an sample:
<script type="text/javascript" src="http://topsite.ucoz.com/stats"></script>
if you run this in html it will sent a mini banner and an hiden iframe with that page.
Use url rewrites in your .htaccess like this:
RewriteEngine On
RewriteRule ^dir/$ /dir/script.js [NC]
The problem with this is that /dir/ cannot be used for anything else.
What you could do is something like this:
RewriteEngine On
RewriteRule ^script/$ /dir/script.js [NC]
However this does not solve the problem of people seeing your code at all. The only solution to that is either code obfuscation or using php (or some other server-side language)
You can configure your web server to have a default page when you call a directory.
This is usually done for index.html
, index.php
, ...
And here say this default is script.js
the server should then deliver it by default
The first one is to a directory and not a file. It doesn't really make sense unless your thinking how on most servers http://abc/index.html goes to http://abc/
Cant really do it and cant see why you'd want to.
Either use the htaccess code listed to rewrite your url or simply fill your index.php with javascript.
and actually, using a url-rewrite would make it pointless having an index.php/index.html there in the first place.
mysite.com/page.php:
<script type="text/javascript" src="/dir/"></script>
mysite.com/dir/index.php:
alert('hello world');
also the sample you listed shows an example of someone using a file, not a whole directory. they simply leave off the extension to their file. Extensions only have semantic value.
I think the main goal here is 'to hide javascript from the user' right?
If you want to hide a javascript, you may want to lookup for 'javascript obfuscation'.
You can't really hide javascript, because it must be able to run on the client browser. Even if you set the default url, as answers stated above, the javascript file will be downloaded.
However, you can obfuscate javascript files so that it will be hard for humans to read while machines can execute it.
There is a question in SO that ask about it.
How can I obfuscate (protect) JavaScript?
精彩评论