R
R
rsitnikov752019-05-18 13:17:47
htaccess
rsitnikov75, 2019-05-18 13:17:47

How to make 301 redirect to public in htaccess in Laravel?

Good day.
There is a site on Laravel
When visiting the url https://site.ru/public/custom-slug and https://site.ru/custom-slug
the same page opens.
How can I write a 301 redirect in htaccess so that when I visit a url with public, it will be redirected to
a url without it.
Now htaccess is like this

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.site.ru$ [NC]
RewriteRule ^(.*)$ https://site.ru/$1 [R=301,L]

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

<Files *.env>
        Deny from all
</Files>
</IfModule>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-05-18
@dodo512

After RewriteEngine on add:

RewriteCond %{THE_REQUEST} /public/
RewriteRule ^public/(.*)$ https://site.ru/$1 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question