Reputation: 4930
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
Upvotes: 1
Views: 340
Reputation: 655239
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.
Upvotes: 2