Karem
Karem

Reputation: 18103

Htaccess only allow JS and CSS files to be viewed?

I would like to have a htaccess rule that restricts only to allow js and CSS files to be viewed.

I would to do this for everything inside /paymethod/.

So this should be viewable:

/paymethod/css/css.css
/paymethod/js/test.js

but not this

/paymethod/js/data.php
/paymethod/else/data.php
/paymethod/else/data.html

( those should work only server side, but they should not be accessed )

Since my Kohana framework already have this:

RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

I added |paymethod , like this:

RewriteRule ^(?:application|modules|system|paymethod)\b.* index.php/$0 [L]

And it works, but this just restricts everything including css and js files.

How can i do this?

Upvotes: 2

Views: 7097

Answers (1)

Croises
Croises

Reputation: 18671

You can use this .htaccess in your paymethod/ directory :

RewriteEngine on 
RewriteCond %{REQUEST_URI} !\.(?:css|js)$ [NC]
RewriteRule ^ - [L,F] 

Or in root .htaccess:

RewriteCond %{REQUEST_URI} !\.(?:css|js)$ [NC]
RewriteRule ^paymethod/ - [L,F] 

Upvotes: 6

Related Questions