Apache RewriteEngine, redirect sub-directory to another script
        Posted  
        
            by 
                Niklas R
            
        on Server Fault
        
        See other posts from Server Fault
        
            or by Niklas R
        
        
        
        Published on 2012-03-22T16:13:34Z
        Indexed on 
            2012/03/22
            17:32 UTC
        
        
        Read the original article
        Hit count: 276
        
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?
© Server Fault or respective owner