1

我希望 URL 重写导致:

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

我试过这个,但它不起作用。我是正则表达式的新手,所以可能有更正的地方:

RewriteRule ^([a-zA-Z]+)/?+([0-9]+)?/? test.php?site=$1&id=$2
RewriteRule ^([a-zA-Z]+)/?+([a-zA-Z]+)?/?+([0-9]+)?/? test.php?site=$1&cmd=$2&id=$3

RewriteRule 应该如何?

提前致谢。

4

1 回答 1

1

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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

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

RewriteRule ^([^/]+)/(\d+)/?$ /test.php?site=$1&id=$2 [L,QSA]

RewriteRule ^([^/]+)/?$ /test.php?site=$1 [L,QSA]
于 2013-08-01T14:15:41.013 回答