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?

1

2 Answers 2

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]
2
  • I used your example, but it is conflicting with the other rules.
    – hskrijelj
    Sep 6, 2013 at 10:53
  • @hskrijelj which one? the one at the bottom? if so use the 2nd rule which is a more exact rule to avoid conflict.
    – Prix
    Sep 6, 2013 at 10:57
0
RewriteRule ^([^/]+)/users/(\w+)$ test.php?site=users&ustr=$1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.