Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何重定向此 URL 字符串: http ://mydomain.com/sub?param1
对此: http: //mydomain.com/sub/param1/
请注意,没有为 param1 设置值,只是为查询字符串设置了“param1”。
为了捕获查询字符串,您需要使用%{QUERY_STRING}:
%{QUERY_STRING}
RewriteCond %{QUERY_STRING} !^$ RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^sub$ /sub/%1/? [R=301,L]
但是,如果没有http://mydomain.com/sub/param1/或有任何规则可以捕捉到它,它仍然会失败。
http://mydomain.com/sub/param1/
http://mydomain.com/sub仅当包含附加的非空查询字符串时,上述条件才设置为重定向。
http://mydomain.com/sub