Removing index.php from website URLs

I am using the Kohana framework (but I think it doesn't matter for this question) and the pages can be accessed like this

http://www.example.com/articles/
http://www.example.com/index.php/articles/

Now, as a rule, I usually try to configure my .htaccess to allow only one path for the page and quietly redirect to other common ways.

Essentially, in the first URL, the address is actually redirected to the second example.

What I want to do is make all the URLs of the second type turn into URLs of the first type. I'm not often sure about .htaccess, and my first attempt throws unexpected results (like endless loops)

Here is what I came up with

RewriteRule ^index\.php/(.*) $1 [NC,L,R=301]

Can someone tell me what I'm doing wrong, and if you encounter this problem, how did you solve it?

EDIT

.htaccess, .

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /~toberua/


# file not found page
    ErrorDocument 404 /404/
    ErrorDocument 403 /403/

# get people out of my directories
    Options -Indexes

# default page to load
    DirectoryIndex index.php

# add trailing slash if missing
    RewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ $1/ [NC,R=301,L]

# redirect /favicon.ico requests
     RewriteCond %{REQUEST_URI} !^/images/layout/favicon\.ico [NC]
     RewriteCond %{REQUEST_URI} favicon\.(gif|ico|png|jpe?g) [NC]
     RewriteRule (.*) images/layout/favicon.ico [R=301,L]

# send /home back to TLD
     RewriteRule home/ $1  [NC,R=301,L]

# ensure there is no /index.php in the address bar
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
    RewriteRule ^(.*)index\.php$ $1 [R=301,L] # this was my attempt to stop /dir/index.php and make it simply /dir/

    RewriteRule ^index\.php/(.*) $1 [NS,NC,L,R=301]

# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]
+3
1

:

RewriteRule ^index\.php/(.*) $1 [NS,NC,L,R=301]

, , , , , , . , / /index.php/articles, /index.php/articles /articles 301 , . . NS , , , , , 301 /articles → /index.php/articles rewrite ( ).

+3

Source: https://habr.com/ru/post/1709001/


All Articles