How to release access to the Public folder

0

Hello, I'm trying to use htaccess to redirect a project, but I have encountered a problem with accessing my Public folder, where my assets are.

Below is my .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d

    RewriteCond Public/$1 -F
    RewriteRule (.+) Public/$1 [L]
    RewriteCond $0 !^(index\.php|Public/)

    RewriteRule ^(.*)$ index.php?key=$1 [QSA]
</IfModule>

The problem that happens is as follows:

When I call my masterpage <script src="Public/css/styles.css"> it throws the value Public/css/styles.css to index.php?key=$1 ...

I needed to access the Public / css folder and make the normal css / js call.

    
asked by anonymous 23.04.2015 / 15:36

1 answer

1

The first rule already does this, it does not need RewriteCond Public...

RewriteEngine On

RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?key=$1 [L,QSA]

This other way should do what you want but I do not like it very much

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.(gif|jpg|png|jpeg|css|js|swf)$ /<public>/$1.$2 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]

Then just change the root folder where the assets are in case I think /$1.$2

    
23.04.2015 / 16:32