J. Wenston J. Wenston - 1 month ago 4x
Apache Configuration Question

Apache2 - Redirect when "path"/query is given after "/index.php"

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?


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".