treznik
treznik

Reputation: 8124

Apache modrewrite htaccess problem

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!

Upvotes: 0

Views: 103

Answers (1)

Gumbo
Gumbo

Reputation: 655239

Try this rule:

RewriteCond $0 !^frontend/
RewriteRule .* frontend/$0 [L]

Upvotes: 2

Related Questions