Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using Apache HTTPD server and I have a 3 static folders on my root, namely "css", "js" and "images". How do I rewrite it so that it can't be seen from the outside world? I know they're static resources and should be seen by the world but I have some configurations in place where they are replaced by CDN urls on my site.

So what I want to do is make requests to these paths a 404. I currently have this code:

 RewriteEngine On
 RewriteCond %{REQUEST_URI} ^/?(css|js|images)/
 RewriteRule ^/?(.*)$ - [G]

G for gone, and I've tried F for forbidden too. But all I want is a 404. The second thing is, if you type www.domain.com/css, it redirects/resolves to www.domain.com/css/ and gives the gone message. I simply dont want to give the inquisitive user a clue that the folders are there.

Thanks.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Why the very specific need for a 404? There's really no reason that a 403 shouldn't work.

I'd say just block them without needing rewrites (in location blocks, directory blocks, or htaccess, take your pick)...

Order allow,deny
Deny from all

but if you really do need a 404, and you can't just delete the files, then rewrite the paths to a nonexistent file, I guess. Really though, there's no reason to do this and you're over-complicating your config.

RewriteCond %{REQUEST_URI} ^/(css|js|images)/
RewriteRule ^.*$ /nonexistentfile.html
share|improve this answer
    
This answers the other half of my question. Im going to give the correct answer to Shane Madden because Ignacio Vazquez-Abrams has 15.8k rep already. But both answers are correct. Thanks you guys! –  Ramon A. Apr 25 '11 at 4:02
add comment

Make the trailing slash optional.

RewriteCond %{REQUEST_URI} ^/?(css|js|images)/?
share|improve this answer
    
This was what I was looking for, but the other half of my question (404) was answered by Shane Madden by rewriting the request to a non-existent file. Thanks to both you guys! –  Ramon A. Apr 25 '11 at 4:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.