I've been trying to rewrite a specific file I have, /u.php/example to just /u/example with htaccess. The /example part I will get and use through php url parsing.
So, another question I read suggested using the following code
RewriteCond %{THE_REQUEST} /(u|a)\.php [NC]
RewriteRule ^ /%1 [L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [L]
But that does not preserve the /example from /u.php/example when rewritten, and causes a 500 error if I just enter /u/example.
Is there a work around for this? What could be the problem? I haven't been able to find a solution on Stack.
You need to capture and redirect the /example
part from URI
RewriteCond %{THE_REQUEST} /(u|a)\.php/([^\s]*) [NC]
RewriteRule ^ /%1/%2 [L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/(.*)?$ /$1.php/$2 [L]