Hammad
Hammad

Reputation: 2137

Match all the strings except www in URL rule apache 2

Here is my rule in URL manager of the application running with apache2 and mod_rewrite enabled:

'http://<username:\w+>.domain.com' => 'public/profile',

I want to rule to match in all the cases except when username is www. Means that when username is substituted with www then it should not pass. It should match in all the cases. I have done this but it's not working:

'http://<username:(?!www)([a-z0-9_-]+)\w+>.domain.com' => 'public/profile'

What I am doing wrong?

Upvotes: 1

Views: 42

Answers (1)

anubhava
anubhava

Reputation: 785581

You can use a negative lookahead to skip the rule when it starts with www.:

'http://<username:(?!www\.)\w+>.domain.com' => 'public/profile',

(?!www\.) is a negative lookahead to assert failure when we have www. at the start.

Upvotes: 1

Related Questions