0

I want to redirect every request with a "path" after the "index.php" to my domain or, if it's not possible, directly to the index.php, but I don't know the RewriteRule/RewriteCond for this case.

For example, I want to redirect www.example.com/index.php/test, www.example.com/index.php/test/hello.php, www.example.com/index.php/test/admin/interface etc. to www.example.com (or www.example.com/index.php).

I don't want to redirect any other file or directory (like www.example.com/admin or www.example.com/interface/admin.php) to my index.php, just any "path" that is given after "/index.php" in the URL. Of course, I also don't want to redirect www.example.com/index.php or www.example.com to itself ending in a redirect loop.

Does anybody know a solution (RewriteRule/RewriteCond) for this?

J. Wenston
  • 5
  • 1
  • 5
  • Refer this http://stackoverflow.com/a/18406686/6374322 – Vignesh Chinnaiyan Sep 21 '16 at 09:33
  • `RewriteEngine on RewriteRule ^.+$ /index.php [L]` This will redirect every query to the root directory's index.php – Vignesh Chinnaiyan Sep 21 '16 at 09:39
  • Thank you for your answers, but I don't want to redirect every non-existing file or directory to the index.php (RewriteCond %{"REQUEST_FILENAME} !-f" or "RewriteCond %{REQUEST_FILENAME"} !-d), because I have a custom error 404 page. I only want to redirect any "path"/query that is **given after "/index.php" in the URL** to index.php without following paths/query and not any path/query or any not existing path or file in general. – J. Wenston Sep 21 '16 at 09:39

1 Answers1

0

This will match only requests that have index.php plus slash and anything after:

RewriteCond %{THE_REQUEST} /index.php/.*$
RewriteRule ^ index.php [R=302]

You didn't specify if you want to do anything with the original request so I'm dropping it here and just doing a redirect. 302 is "found", replace with 301 if you want "permanently moved".

Vrac
  • 1,054
  • 1
  • 8
  • 15