views:

319

answers:

1

I've got a REST framework that when plopped into any directory should Just Work(TM), and it seems to work fine when I've got projects in subdirectories, but not if it's in root. So, given a few example directories;

/
/project1
/bingo/project2
/hoopla/doopla/minor/project3

All of these works fine, except I'm getting "funnies"* when the project runs in the root directory (bit hard to explain, I suppose, but the second level rewrites are not working properly). Here's my attempt at a generic .htaccess file:

RewriteEngine On
RewriteRule ^static/ - [L]
RewriteCond %{REQUEST_URI} ^$
RewriteRule .* ./ [R,L]
RewriteRule ^index.php - [L]
RewriteRule (.*) index.php?q=$1 [QSA,PT]

(And yes, all projects have a subdirectory ./static which is ignored by rewrites) What I'm trying to achieve is a set of rewrite rules that work for most cases (which is, again, plonking the project in a directory the webserver serves). I'm not a rewrite rules wiz by a long shot, and any good advice and gotchas would be appreciated (and yes, I've gone through too many introductory articles. I need some serious juice.)

  • More info on the funnies; my webserver has docroot in one spot (under /usr/share/apache2/default-site/), but a set of rules that says that /projects is pulled in from somewhere else that's not a subdirectory of docroot (/home/user/Projects/). When I go there, I get a list of /projects subdirectories, and if one of those subdirectories gets called (restmapp) with the proposed rewrite rules, I get ;

    The requested URL /home/user/Projects/restmapp/index.php was not found on this server.

A: 

Try these rules:

RewriteRule ^static/ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?q=$0 [L,QSA]


Edit   Additionally you could use the R flag to force an external redirect or activate the logging feature of mod_rewrite to see how the requests are rewritten/redirected internally.

Gumbo
Hmm, doesn't seem to work. I get 404 on index.php (but the right path is stated) so it's a bit confusing, and I'm suspecting a recursive thing? Either that or I've got some other weird config in my setup. I'll double check, though.
AlexanderJohannesen
Some more information on debugging would be helpful.
Gumbo