Reputation: 40
I have a website with a dynamic main page, in which only one image changes, the url looks like this:
http://mysite.com/?v=imagename.jpg
i am trying to find a rule to redirect all these url's to:
I have tried:
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)v=([^&]+)&?(.*)?$
RewriteRule ^index\.php$ http://mysite.com/3?%1%4 [L,R=301]
and:
RewriteRule ^index.php?v=([a-zA-Z]+)/([0-9]+)$ http://mysite.com/$1
and countless other variations, but nothing seems to work .. what am i doing wrong?
Upvotes: 0
Views: 425
Reputation: 143866
To redirect a browser accessing the URL with the query string to the URL without, you need to do this:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?v=([^&\ ]+?).jpg&?([^\ ]*)
RewriteRule ^ /%2?%3 [L,R=301]
Then after the browser gets the redirect, it'll try to request the URL without the query string. If there isn't actually any content at /imagename
then you'll need to rewrite them back to the query string'ed URI:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /?v=$1.jpg [L,QSA,NC]
Upvotes: 1