0

我正在对我的网站进行 URL 重写。到目前为止,它工作得很好。我得到以下代码:

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]

使用上面显示的代码,我有这些 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

我想要一个规则。我想

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

我怎样才能使这项工作?

4

2 回答 2

1

我想这会起作用:

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

但是,如果在用户上也可能有没有破折号的用户,那么您必须通过以下方式使其更具体:

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

否则它会与您的其他规则相冲突。

以及完整的规则:

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]
于 2013-09-04T23:42:32.327 回答
0
RewriteRule ^([^/]+)/users/(\w+)$ test.php?site=users&ustr=$1
于 2013-09-04T22:36:55.860 回答