0

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?

1 Answer 1

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

RewriteCond     %{REQUEST_URI}          !^/files/$
RewriteRule     ^/?(.*)$                index.php?$1
6
  • 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, 2012 at 18:43
  • sry about that, went a little too fast. updated answer Mar 22, 2012 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, 2012 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, 2012 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, 2012 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .