0

I am working on the URL-rewrite of my site. So far, it works great. I got the following code:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /calendster/

RewriteRule ^admin2($|/) - [L]
RewriteRule ^test.php($|/) - [L]

RewriteRule ^([^/]+)/([a-z]+)/(\d+)/?$ index.php?site=$1&cmd=$2&id=$3 [L,NC,QSA]
RewriteRule ^([^/]+)/([a-z]+)/?$ index.php?site=$1&cmd=$2 [L,NC,QSA]
RewriteRule ^([^/]+)/(\d+)/?$ index.php?site=$1&id=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?site=$1 [L,QSA]

With the code showed above, I have these URL-re

test.php?site=hi  --> www.domain.com/hi
test.php?site=hi&id=1  --> www.domain.com/hi/1
test.php?site=hi&cmd=test  --> www.domain.com/hi/test
test.php?site=hi&cmd=test&id=1  --> www.domain.com/hi/test/1

I would like one more rule. I would like to

test.php?site=users&ustr=haris-skrijelj  --> www.domain.com/users/haris-skrijelj

How can I make this work?

Prix
  • 19,417
  • 15
  • 73
  • 132
hskrijelj
  • 433
  • 5
  • 16

2 Answers2

1

I guess this would work:

RewriteRule ^([^/]+)/([a-z-]+)/?$ index.php?site=$1&ustr=$2 [L,NC,QSA]

However if on users it's also possible to have users without a dash then you would have to make it more specific with:

RewriteRule ^(users)/([a-z-]+)/?$ index.php?site=$1&ustr=$2 [L,NC,QSA]

Or it will conflict with your other rule.

And the complete rule:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /calendster/

RewriteRule ^admin2($|/) - [L]
RewriteRule ^test.php($|/) - [L]

RewriteRule ^([^/]+)/([a-z]+)/(\d+)/?$ index.php?site=$1&cmd=$2&id=$3 [L,NC,QSA]
RewriteRule ^([^/]+)/([a-z-]+)/?$ index.php?site=$1&ustr=$2 [L,NC,QSA]
RewriteRule ^([^/]+)/([a-z]+)/?$ index.php?site=$1&cmd=$2 [L,NC,QSA]
RewriteRule ^([^/]+)/(\d+)/?$ index.php?site=$1&id=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?site=$1 [L,QSA]
Prix
  • 19,417
  • 15
  • 73
  • 132
0
RewriteRule ^([^/]+)/users/(\w+)$ test.php?site=users&ustr=$1
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405