How to free access to Public folder

Asked

Viewed 569 times

0

Hello, I am trying to use htaccess to redirect a project, but I have encountered a problem regarding access to my Public folder, where my Assets are located.

Below follows 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 this:

when I make the call on my masterpage <script src="Public/css/styles.css"> he plays the value Public/css/styles.css to the index.php?key=$1...

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

1 answer

2


The first rule already does not need the 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 don’t 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 by the root folder where you have the Assets in case I think /$1. $2

  • So you’re not doing it, because when I’m on for example site.com/users/list my src="public/Assets" try to access site.com/users/public

  • puts the absolute path in the link /public/Assets

  • I don’t remember where I had read about it, but I did say that using Absolute paths was not a good practice

  • it is not a good practice your application does not work

  • this is a very interesting point too

Browser other questions tagged

You are not signed in. Login or sign up in order to post.