views:

31

answers:

1

I am a rewrite newbie, I am wondering why this rewrite rule is not working, it ceases Apache from starting

RewriteRule ^([-a-zA-Z0-9_]+)?/constant/([-a-zA-Z0-9_]+)/(.*)$ http://$2.domain.com/$1/$3 [R=301, NC]

What this rule should do is URL refactoring, examples:

http://www.domain.com/controller/constant/variable/action should be redirected to http://variable.domain.com/controller/action

and

http://www.domain.com/constant/variable should be redirected to http://variable.domain.com

basically /constant/variable should be detected, inserted in the subdomain and then removed

Please help me in this subtle problem that I am facing.

Thanks

+1  A: 

Try it with two rules:

RewriteRule ^constant/([-a-zA-Z0-9_]+)$ http://$2.domain.com/$1 [R=301,NC]
RewriteRule ^([-a-zA-Z0-9_]+)/constant/([-a-zA-Z0-9_]+)/(.*)$ http://$2.domain.com/$1/$3 [R=301,NC]

Also note that the flags must not contain any whitespace: [R=301, NC] is invalid syntax but [R=301,NC] is valid syntax.

Gumbo
It didnt get me syntax error, but it didnt work either :(
wael34218
Thanks it worked, i was just not paying attention
wael34218