Pergunta

I'm trying to set the first rule as optional, so both of these URLs will work:

  • /username
  • /username/history
  • /history

The username will never clash.

RewriteRule ^([a-z]+)/((history|analysis|messages|photos)?)$ pages/dashboard.php?username=$1&page=$2 [L]

With the above I have /username/history working. Cannot figure howto get the others.

EDIT: The above snippet is the result of trying to merge these three lines into one.

RewriteRule ^(history|analysis|messages|photos)?$ pages/dashboard.php?page=$1 [L]
RewriteRule ^([a-z]+)/(history|analysis|messages|photos)?$ pages/dashboard.php?username=$1&page=$2 [L]
RewriteRule ^([a-z]+)$ pages/dashboard.php?username=$1 [L]
Foi útil?

Solução

You can use this rule:

RewriteRule ^(history|analysis|messages|photos)/?$ pages/dashboard.php?page=$1 [L,NC,QSA]

RewriteRule ^([a-z]+)(?:/(history|analysis|messages|photos))?/?$ pages/dashboard.php?username=$1&page=$2 [L,NC,QSA]
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top