Forum Moderators: phranque
let's say I have this path to a file on the filesystem
/webroot/dir1/filename.php
and I have this url
example.com/dir1/filename/more/stuff
I want to rewrite to
example.com/dir1/filename.php/more/stuff
So I have a simple rewrite rule that works fine
RewriteBase /dir1
RewriteRule (.*)/filename/(.*) $1file.php$2 [L]
It finds /webroot/dir1/file.php just as I want.
The problem is, as soon as I put another file in that same directory dir1 that has the same basename, but a different extension (e.g file.css), the server tries to find it instead, but rewrites to
/webroot/dir1/filename.css
Even if I put in a RewriteCond like
RewriteCond %{REQUEST_URI}!.*\.(css¦gif¦jpg).*
it doesn't seem to help. I've tried a bunch of permutations, but I just can't get it to do what I want.
<Files filename>
ForceType application/x-httpd-php
</Files>
Apache2 also needs
acceptpathinfo on
The first few lines of the script "filename" parse the parameters
$dirname = getenv("REQUEST_URI");
if (substr($dirname,-1,1)!= "/") {
$dirname = $dirname."/";
}
$dirname = split("/", $dirname);
I have a bit of stuff that checks it's the correct form as well. You can figure that out because it's going to be specific.
Jim
I've never had to use RewriteBase on any properly-configured server... Not sure if that is just luck or what.
I tried it on another server and sure enough... success.
This set of rules covers all the cases I can think of and obviates the need for the RewriteCondition
RewriteEngine On
RewriteRule (.*)farmers/farm-dir/(.*) $1farmers/farm-dir.php/$2 [L]
RewriteRule (.*)farmers/farm-dir$ $1farmers/farm-dir.php [L]
RewriteRule (.*)farmers/farm-dir\?(.*) $1farmers/farm-dir.php?$2 [L]
I'm still not sure why that doesn't work on the first server. It's so simple and other rewrites have worked fine, but for whatever reason, it just doesn't work there. Since the non-working server is just my "playstation", I don't really care.