wordpress - mod_rewrite replace query string key -
in short, i'm trying change given url:
http://mydomain.com/category/title/attachment/randomstring_?resolution=320x480
with
http://mydomain.com/category/title/attachment/randomstring_320x480
in essence, removing ?resolution=
query string , adding value path.
the category, title, , randomstring values dynamic, placement should same.
i don't know if matters, being used in wordpress.
i tried following, 404:
<ifmodule mod_rewrite.c> rewriteengine on rewritebase / rewritecond %{query_string} ^resolution=([0-9]{3,4}x[0-9]{3,4})$ rewriterule ^$ ${request_uri}%1/? [r] rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /index.php [l] </ifmodule>
any appreciated ;)
well, after lot of trial , error (and reading rewritelog output), got working following:
<ifmodule mod_rewrite.c> rewriteengine on rewritebase / rewriterule ^index\.php$ - [l] rewritecond %{query_string} ^resolution=(.*)$ rewriterule . %{request_uri}%1? [r=301,l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /index.php [l] </ifmodule>
the key issues original solution:
- using
^$
instead of.
inrewriterule
- using
/?
instead of?
inrewriterule
- not including
,l
inrewriterule
flags
for curious, including ?
in rewriterule
prevents query_string remaining in request.
Comments
Post a Comment