htaccess With a different amount of variables

痴心易碎 提交于 2019-12-11 09:05:02

问题


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]


来源:https://stackoverflow.com/questions/10770035/htaccess-with-a-different-amount-of-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!