htaccess的重定向URL参数作为段 [英] htaccess redirect url parameter as segment

查看:228
本文介绍了htaccess的重定向URL参数作为段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能重定向URL参数在.htaccess文件片段?

 测试/的index.php?参数= myvalue的
 

 测试/ myvalue的/
 

解决方案

是的。试试这个:

 的RewriteCond%{QUERY_STRING}参数=(。*)
重写规则测试/索引\ .PHP测试/%1
 

据什么是匹配的?在之后的 mod_rewrite的文档,查询字​​符串(部分)中分离到的 QUERY_STRING 变量,然后必须单独从URL的主要部分进行测试。在的RewriteCond ,该参数值由常规的前pression括号内捕获(。*),并随后可通过%1 重写规则

Is it possible to redirect url parameters as segments in .htaccess file?

i.e.

test/index.php?parameter=MYVALUE

to

test/MYVALUE/

解决方案

Yes. Try this:

RewriteCond %{QUERY_STRING} parameter=(.*)
RewriteRule test/index\.php test/%1

According to "What is matched?" in the mod_rewrite docs, the query string (part after the ?) is separated out into the QUERY_STRING variable, which then has to be tested separately from the main part of the URL. In RewriteCond, the parameter value is captured by the regular expression within the parentheses (.*), and is then available as %1 in the RewriteRule.

这篇关于htaccess的重定向URL参数作为段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆