Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

RewriteEngine   on
RewriteRule     ^/?$                    index.php
RewriteRule     ^/files/?(.*)$          /requestfile.php?$1

RewriteCond     %{REQUEST_URI}          !^/files/$
RewriteRule     ^/?(.*)$                index.php?$1
share|improve this answer
    
That doesn't change the problem. I wouldn't even need to test it (Anyway, I did!). The problem is that after the line you quoted the URL is rewritten once again to be index.php?requestfile.php. –  Niklas R Mar 22 '12 at 18:43
    
sry about that, went a little too fast. updated answer –  Mathias R. Jessen Mar 22 '12 at 18:56
    
hm, still don't get what this will change no (replacing + with * and adding / in fron of requestfile.php$1). This still does not prevent mod_rewrite to rewrite the URL rewritten by this rule once again with the ^/?(.*)$ rule. –  Niklas R Mar 22 '12 at 18:59
    
Hm, seeing your recent edit, I'm going to try that one. I already tried to use ! in front of a regular expression, but that didn't seem to work.. Anyway, gonna tell'ya in a minute, and thanks for your help so far! –  Niklas R Mar 22 '12 at 19:07
    
Ok, that regular expression in the condition does work. But I need the REQUEST_URI not to match /requestfile\.php so that would be RewriteCond ... !/requestfile\.php. I'm going to take a look into the rewrite-log why it doesn't work this way. –  Niklas R Mar 22 '12 at 19:34
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.