Q
Q
Qairat2018-03-06 17:08:03
htaccess
Qairat, 2018-03-06 17:08:03

How to properly redirect address in .htaccess?

It is necessary to make it so that if the request goes to / api then redirect to index.php,
if you just went to the site then to index.html
Here are the files in the folder
5a9e9ff4568a6545356045.png
and here is what I wrote in the htaccess file

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

    RewriteEngine On

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

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

    # Handle Front Controller...

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.html [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^api index.php [L]


</IfModule>

Opens when I go to the site, index.php. Where is the mistake? What is the best way to redirect?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2018-03-07
@shambler81

1. change the priority of the forced index file to html, as a rule php has a higher priority

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^api index.php [L]

must be above the main NC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question