N
N
Nikita2017-10-21 23:46:33
htaccess
Nikita, 2017-10-21 23:46:33

How to properly set up a request redirect in .htaccess?

Good day to all!
Please help me with .htaccess
There is a site root. It contains the .htaccess file, which should redirect all requests to the /public folder.
Here is its content:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^(.*)/$ /$1 [L,R=301]
  RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

The /public folder contains the second .htaccess file, which redirects all requests to index.php in the same folder:
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

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

Everything works as it should, except for one thing: when accessing the /public/images folder (on request in the browser sitename.ru/images), the URL changes to sitename.ru/public/images and the message "Forbidden" pops up.
Everything is as it should be, except for the public folder in the URL.
Please tell me how to remove it
Thank you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2017-10-24
@shambler81

I think it's obvious
, as I understand it, you filed your CNC there.
And therefore, the laws are the same
if you need to exclude all directories

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/$1 [L]

well, or specify the directory in more detail with the negation of "!"
RewriteCond %{REQUEST_URI} !^/images/.*
RewriteRule ^(.*)$ public/$1 [L]

well, or by mask to the static content in this folder, there is already your desire
, and so on ...
RewriteCond - in fact, this is IF
there can be as many as you like, after them the steering wheel is THEN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question