当其中有一个特殊参数时,例如/ post / path /?code = 1重定向到/ post / path /,我想将URL重定向/ RewriteRule。
我不知道,但这在这里不起作用
RewriteEngine on
RewriteBase /
RewriteRule ^.*code=1.*$ /post/path/ [L]
如果我运行http://domain.com/post/path/?code=4/oWTYGaoOsyts,则不会有任何变化。
[REQUEST_URI] => /post/path/?code=1/oWTYGaoOsyts
[SCRIPT_NAME] => /index.php
[PHP_SELF] => /index.php
要在URL中搜索参数,您需要使用RewriteCond和%{QUERY_STRING}:
RewriteCond %{QUERY_STRING} ^.*code=1.*$
RewriteRule .* /post/path/ [L]
从文档中:
语法:RewriteRule模式替换[标志]
在Directory和htaccess上下文中,删除导致服务器到达当前RewriteRule的前缀(例如,“ app1 / index.html”或“ index.html”,具体取决于指令的位置)之后,Pattern将首先与文件系统路径进行匹配。定义)。
如果希望与主机名,端口或查询字符串匹配,请分别将RewriteCond与%{HTTP_HOST},%{SERVER_PORT}或%{QUERY_STRING}变量一起使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句