azz0r
azz0r

Reputation: 3311

.htaccess catching mixed URL

I'm trying to match these three routes:

system/session
teams
teams/529f3d87b3f7e2c73d100000

I have the following rules:

RewriteRule ([-A-Za-z0-9]+)/([-A-Za]+)$ /index.php?__module=$1&__action=$2 [L,QSA]
RewriteRule ^([-A-Za-z0-9]+)$ /index.php?__module=$1&__action=index [L,QSA]
RewriteRule ([-A-Za-z0-9]+)/([-A-Za-z0-9]+)$ /index.php?__module=$1&__action=index&id=$2 [L,QSA]

However, when I goto system/session its catching the rule set for teams/529f3d87b3f7e2c73d100000 and making session = $_GET['id'] and not $_GET['__action']

Is there an obvious solution to this?

Upvotes: 1

Views: 45

Answers (1)

Jon Lin
Jon Lin

Reputation: 143906

That's because your regex is wrong for the first rule:

RewriteRule ([-A-Za-z0-9]+)/([-A-Za-z]+)$ /index.php?__module=$1&__action=$2 [L,QSA]

You're missing the -z part of the range, and only matching "a".

You should also go ahead and add ^ matches to them all:

RewriteRule ^([-A-Za-z0-9]+)/([-A-Za-z]+)$ /index.php?__module=$1&__action=$2 [L,QSA]

Upvotes: 1

Related Questions