Rewriting directory

I’m trying to redirect all files from directory /cache/ to file /cache.php

This is the rule I’m using:

RewriteRule ^/cache/$ /cache.php

and it works perfectly on my localhost.

Problem is, for some reason it doesn’t work on live server. Is there something wrong with that rule or with server configuration? And if its server configuration, where can I fix it (its a virtual server with cpanel/whm, I have full access)?

Thanks for suggestion, but I don’t want a 301 redirect. In cache.php I check url to show different content, depending on what item from cache is being requested, so I need to keep original url.

Solved.

For some reason it didn’t like / at the beginning of url as well as / at the end of it, but this rewrite rule did the trick:

RewriteRule ^cache\\/(.*) /cache.php

CA,

Actually,

Redirect 301 /cache/ /cache.php

… would have been more appropriate (mod_alias is part of Apache’s core and, thus, runs faster - and this is what a simple Redirect is designed to do).

Regards,

DK

CA,

Okay, drop the 301 as that part is optional.

Regards,

DK

Thank you very much! That’s a much neater solution.

edit: It works perfectly on localhost, but doesn’t work on live server. It tries to do a 301 redirect without “301” in line.

CA,

The Redirect’s redirection MUST be an absolute redirection. If Apache is confused (physical path vs webspace path) then you can use an external absolute redirection, i.e., http://your.domain.com/cache.php.

Regards,

DK

It is absolute, but apache still uses 301 redirect. As I mentioned above, I don’t want url to be changed, so I don’t want a 301 redirect.

If you don’t specify a 301, it’s supposed to make a 302 (temporary) redirect - at least mod_rewrite works that way. If you want to make a 302 redirect with mod_alias’s Redirect, specify it by replacing the 301 I used with 302.

Regards,

DK