htaccess With a different amount of variables

2019-07-25 00:21发布

问题:

I have a website that on one specific page it requires an extra variable.

At the moment, the htaccess I am using is:

RewriteEngine On
RewriteRule ^([^/]*)/$ /index.php?page=$1 [L]

Which works fine with one variable.

How would I get it to work with : http://tessite.com/index.php?page=test&id=1

So it looked like: http://tessite.com/test/1

Thanks for any help or replies.

回答1:

RewriteEngine On
RewriteRule ^(.*)/(.*)/$ /index.php?page=$1&id=$2 [L]
RewriteRule ^(.*)/$ /index.php?page=$1 [L]

Just add $2!

Also, [^/] isn't required, you can simply use ..



回答2:

It can be coded like this:

RewriteRule ^([^/]*)/([^/]*)/$ index.php?page=$1&id=$2 [L]