V
V
volodec2017-06-01 07:56:08
htaccess
volodec, 2017-06-01 07:56:08

How to get rid of index.php in address using .htaccess in laravel?

Hello, I have a question about configuring .htaccess in Laravel.
Previously, my site was written by me on my own without CNC, eventually moved to Laravel. search engines in the list of indexed and searched pages have pages like site.ru/index.php?query=123 and do not throw them out of the index, these pages open the main one and are not redirected to /. Everything would be fine, they would eventually be deleted as duplicates, but the files registered via url() change their addresses to site.ru/public/index.php/build/css/style-abc123.css .
At the root of the site there is .htaccess with the following code:

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

In the public folder, standard from laravel:
<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]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

</IfModule>

I ask for help in setting up a redirect from index.php?query=123 to /?query=123
PS: Other addresses like site.ru/articles work as they should

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Kyznetsov, 2017-06-01
@360157

.htaccess
cool of course, but I would also like to take a look at the capital routs
on my site like this:
Site root (domain/www/{laravelfile})
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
     # Options +FollowSymLinks
RewriteEngine On

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

</IfModule>

and (domain/www/{laravelfile}/public)
<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]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

V
Viktor Taran, 2017-06-01
@shambler81

Do I understand correctly that you had a site without CNC and with GET requests.
Now your urls are normal and you have redirected all old urls to the new site to the root ?
If so then
1. collect a complete list of old indexed urls.
2. Accordingly, in Excel, collect a list of new urls according to the principle old url new url.
3. Let's party girl here.
4. If you don’t care about SEO, then, as far as I understand, you have a problem that get requests remain in the URL.
So this is solved very simply
^(.*)/$ /$1\?the question at the end of the redirect will delete all get requests, BUT BECAUSE you do not have a list of old get requests, your rule will cut off all local ones if they exist.
So go back to point 1.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question