URL rewriting in HTACCESS ignoring existing files and folders

0

When I am going to pass a website on the server I put a .htaccess file with this code below:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

This code makes typing the site:

  

www.dominio.com.br

Enter direct in the index.php of the folder public of Laravel .

But now there is a problem. I have a panel that is in a painel folder, outside of the Laravel% folder, which is independent of Laravel .

But when I type:

  

www.dominio.com.br/painel

Do not enter.

And even though I put the public folder inside the painel folder, it also does not. Because of public within the .htaccess folder.

How can I leave this URL separate?

    
asked by anonymous 10.12.2015 / 14:21

2 answers

2

This occurred because you did not check if the folder exists and another detail instead:

RewriteRule ^painel - [L]

Prefer this:

RewriteRule ^painel/ - [L]

Without the bar the .htaccess will accept addresses as localhost/painel2 and assuming it is a route it will become inaccessible.

Returning to the problem, you probably did something similar to this in your .htaccess: link

First solution

You should be using something like this:

/home
  |--- /user
         |--- /public_html
                |--- .htaccess (seu .htaccess)
                |--- /public
                        |--- index.php
                        |--- .htaccess
                |--- /app
                |--- /bootstrap
                |--- /config
                |--- /database
                |--- /painel (pasta do painel)

If you want the panel folder here to be accessible, public_html/.htaccess should look like this:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/ [L]

Second Solution

However, the best thing is that everything is inside public itself, so the structure would be that of the folders being this ( public_html is a common folder in servers, may have another name like www ), the location of the folder panel into public :

/home
  |--- /user
         |--- /public_html
                |--- .htaccess (seu .htaccess)
                |--- /public
                        |--- /painel (pasta do painel)
                        |--- index.php
                        |--- .htaccess
                |--- /app
                |--- /bootstrap
                |--- /config
                |--- /database

Then in this case the file public_html/.htaccess must contain:

RewriteEngine On

RewriteRule ^ public/ [L]

And the public_html/public/.htaccess file should contain:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Third solution

But I have to say one thing, you can even use .htaccess to point everything to public , however the best way is to set DocumentRoot to be public of Laravel or else drop public in public_html and the laravel folders will be out, something like:

/home
   |--- /user
         |--- /app
         |--- /bootstrap
         |--- /config
         |--- /database
         |--- public_html (conteúdo de public deve ficar nesta pasta)
              |--- /painel (pasta do painel)
              |--- index.php
              |--- .htaccess
    
27.12.2015 / 15:42
1

Hand, this OS is top.

I think there is some power hanging around here ... there are questions I ask here and not long after, a matter of minutes I solve my problem.

How do you do it?

To leave the URL 'independent' I typed like this:

RewriteRule ^painel - [L]

Looking like this:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^painel - [L]
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
    
10.12.2015 / 14:26