Apache RewriteEngine, redirect sub-directory to another script
- by Niklas R
I've been trying to achieve this since about 1.5 hours now. I want to have the following transformations when requesting sites on my website:
homepage.com/ => index.php
homepage.com/archive => index.php?archive
homepage.com/archive/site-01 => index.php?archive/site-01
homepage.com/files/css/main.css => requestfile.php?css/main.css
The first three transformations can be done by using the following:
RewriteEngine on
RewriteRule ^/?$ index.php
RewriteRule ^/?(.*)$ index.php?$1
However, I'm stuck at the point where all requests to the files subdirectory should be redirected to requestfile.php. This is one of the tries I've done:
RewriteEngine on
RewriteRule ^/?$ index.php
RewriteRule ^/?files/(.+)$ requestfile.php?$1
RewriteRule ^/?(.*)$ index.php?$1
But that does not work. I've also tried to put [L] after the third line, but that didn't help as I'm using this configuration in .htaccess and sub-requests will transform that URL again, etc. I fuzzed with the RewriteCond command but I couldn't get it to work.
How needs the configuration to look like to achieve what I desire?