问题描述:

How do I redirect this URL string:

http://mydomain.com/sub?param1

To this:

http://mydomain.com/sub/param1/

Note, there is no value set for param1, just "param1" for the query string.

网友答案:

In order to capture the query string, you need to use %{QUERY_STRING}:

RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^sub$ /sub/%1/? [R=301,L]

However if there is no http://mydomain.com/sub/param1/ or any rule to catch that it would still fail.

The above condition is set to redirect only if http://mydomain.com/sub contains a non empty query string attached.

相关阅读:
Top