问题描述
我正在尝试使用get参数转换网址
localhost:8080/goto/?fruits=1&apples=2
进入
localhost:8080/fruits/1/apples/2
使用以下命令:
RewriteEngine On
RewriteCond %{QUERY_STRING} !apples [NC]
我可以验证所访问的网址是否具有苹果,水果或附加的get参数,以区分具有不同关键字(例如berrys = 1或melons = 7等)的多个网址。
使用以下命令
RewriteRule ^ fruits/([^/]*)/apples/([^/]*)$ goto/index.php?fruits=$1&apples=$2 [L]
我可以将localhost:8080 / fruits / 1 / apples / 2更改为localhost:8080 / fruits / 1 / apples / 2
如何优化RewriteCond中的命令以在RewriteRule中使用$ 1,$ 2等多个键和值来不对多行进行硬编码?不喜欢:
RewriteEngine On
RewriteCond %{QUERY_STRING} !apples [NC]
RewriteRule ^fruits/([^/]*)/apples/([^/]*)$ goto/index.php?fruits=$1&apples=$2 [L]
RewriteCond %{QUERY_STRING} !melons [NC]
RewriteRule ^fruits/([^/]*)/melons/([^/]*)$ goto/index.php?fruits=$1&melons=$3 [L]
RewriteCond %{QUERY_STRING} !berrys [NC]
RewriteRule ^fruits/([^/]*)/berrys/([^/]*)$ goto/index.php?fruits=$1&berrys=$3 [L] ....
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)