1

I have this rule for redirect from index.php

RewriteCond %{HTTP_HOST} ^(.*):443$ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^/index.php$ [NC]
RewriteRule ^(.*)index\.php$ https://%1/$1 [L,R=301]

But it works only for address: site.com/index.php to site.com I need to redirect from all adress who contain index.php, for example site.com/categories/rings/index.php to site.com/categories/rings/ Thanks!

2 Answers 2

1

Your RewriteCond rules are the problem:

RewriteRule ^(.*/)?index\.php$ https://%{HTTP_HOST}/$1 [L,R=301]

If you want to keep the port RewriteCond, you can use this:

RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*/)?index\.php$ https://%{HTTP_HOST}/$1 [L,R=301]
Sign up to request clarification or add additional context in comments.

7 Comments

Unfortunately, this example does not work. It not redirect address site.com/categories/rings/index.php to site.com/categories/rings/
@Serg Try clearing your cache in your browser before testing.
It not redirect url site.com/categories/rings/index.php to site.com/categories/rings/ RewriteCond %{HTTP_HOST} ^(.*):443$ [NC,OR] RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ [NC,OR] RewriteCond %{THE_REQUEST} ^/index.php$ [NC] RewriteRule ^(.*/)?index\.php$ https://%1/$1 [L,R=301]
If url site.com/about/index.php redirect works fine to site.com/about/
@Serg That's the code from your question. Did you try my answer?
|
0

⭐ I use this in my .htaccess file in laravel project

# Redirect index.php to non index.php
RewriteRule ^(.+)/index.(php|html) /$1 [R=301,L]
RewriteRule ^/index.(php|html) / [R=301,L]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.