3

I want create redirect in my htaccess file. From url with index.php to page without index.php, but only for one specific folder "catalog".

For example:

from /catalog/some_folder/index.php to /catalog/some_folder/ or

from /catalog/some_folder/etc/index.php to /catalog/some_folder/etc/

URL like this /catalog2/some_folder/index.php don't must redirect

I try add those lines(localhost because it was xampp):

  RewriteCond %{REQUEST_URI} /catalog/+[^\.]+index.php$
  RewriteRule ^index\.php$ localhost/$1 [R=301,L]

But this didn't work. How can i force this to work right?

4 Answers 4

1

You can use this rule in root .htaccess:

# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(catalog/.+)index\.php$ /$1 [L,R=302,NC,NE]
Sign up to request clarification or add additional context in comments.

2 Comments

something must be wrong in my configuration it is sending me up one level (i am in localhost/myproject/index.php) and (it is sending me to localhost/)
To make it work in /myproject just change target URI in last rule as /myproject/$1
1
RewriteCond %{REQUEST_URI} /index.php
RewriteRule ^(.*)index\.(php)$ https://%{SERVER_NAME}/$1 [R=301,L]

If you need to remove all "index.php" at the end of the address

Comments

0

To remove index.php:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

Remember,you will need to activate mod_rewrite.

Comments

0
RewriteEngine On
RewriteCond %{THE_REQUEST} (?:/[^/]*)*/index\.php[?#\ ]
RewriteRule .* %{REQUEST_URI}/../ [L,R=301]

For me this is working the solution above is sending me to a folder up one level.

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.