In short, I’m trying to change the given URL:
http://mydomain.com/category/title/attachment/randomstring_?resolution=320x480
With
http://mydomain.com/category/title/attachment/randomstring_320x480
In essence, removing ?resolution= from the query string and adding the value to the path.
The category, title, and randomstring values are dynamic, but their placement should always be the same.
I don’t know if it matters, but this is being used in WordPress.
I tried the following, but I just get a 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 help is appreciated 😉
Well, after a lot of trial and error (and reading RewriteLog output), I finally got it working with the following:
The key issues with the original solution:
^$instead of.in theRewriteRule/?instead of just?in theRewriteRule,Lin theRewriteRuleflagsFor anyone who is curious, including
?in theRewriteRuleprevents the QUERY_STRING from remaining in the request.