N
N
NickSunMan2021-04-25 01:23:38
htaccess
NickSunMan, 2021-04-25 01:23:38

How can I change my code in .htaccess so that there is a redirect to site.ru from index.php and index?

Greetings! Please help me change the code so that in the url for the place -> site.ru/index and site.ru/index.php a redirect would work without these endings, namely to site.ru . At the moment, if I enter site.ru/index.php it works ( not found ), and if I enter site.ru/index (the main page with url: site.ru/index just opens ). With the preservation of my other rules: from www to without, non-existent pages get 404, remove the slash at the end.

ErrorDocument 404 /error.php
RewriteEngine on

#Редирект с www на без
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]             
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

#Убирает слэш в конце
RewriteCond %{REQUEST_FILENAME} !-d                   
RewriteRule ^(.+)/$ /$1 [R=301,L]

# Если index. php,   php -> 404
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index$|\.php - [L,R=404]

RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]


I don't know much about .htaccess...
Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question