views:

55

answers:

1

Hi,

I have a rule, that gets up to three parts, separated by a / (slash). They represent /app/controller/action, but they are optional, which means /, /app, /app/controller work as well.

The thing is, I want another rule, before this one, which would set the default app to "frontend", and I think it should look like this:

RewriteRule ^(.*)$ frontend/$1

However, if I have the url /part1 everything is ok and it is received as /frontend/part1. However, if the url contains a / (slash), like /part1/part2 , I get a 500 internal error. If I remove this rule, the initial one works with /frontend/part1/part2, so the problem is within this rule. It seems the $1 does not accept slashes in it. Is that a known fact?

And also, I would like that this rule is not ran if the current url already starts with frontend/, I'm thinking something like this:

RewriteRule ^frontend(/.*)?$ frontend$1 [S=1]

Or could this be done more elegantly with a RewriteCond ?

Thanks!

+2  A: 

Try this rule:

RewriteCond $0 !^frontend/
RewriteRule .* frontend/$0 [L]
Gumbo
Thanks!!! It seems to work.But can you quickly explain why wasn't mine working or what's the difference between your and my solutin?$0 means all the query, right?
treznik
Your solution is probably causing an infinite loop. But my rule excludes any match that begins with `frontend/` to be rewritten to `frontend/…`. And, yes, `$0` contains the match of the entire pattern.
Gumbo