Answer the question
In order to leave comments, you need to log in
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]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question