我希望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应该如何?
提前致谢。
答案 0 :(得分:1)
通过httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在.htaccess
目录下的DOCUMENT_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]