Jordan
Jordan

Reputation: 248

How to remove query string from file name using .htaccess?

So currently I've got a URL like:

http://test.com/images/1/Villa-1_watermark.jpg&width=132&height=123

Ideally I would like to have a .htaccess file within the images directory which removes the query string ("&width=132&height=123") from all of the images located in the sub-directories.

I currently have:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} ^width=([^&]+)&height=([^&]+)$ [NC]
RewriteRule . %{REQUEST_URI}? [L,R]

Any help would be appreciated.

Upvotes: 0

Views: 331

Answers (1)

Sean Bright
Sean Bright

Reputation: 120714

Apache doesn't recognize &width=132&height=123 as the query string because it doesn't have a leading ?. Try this instead:

RewriteEngine on

RewriteRule (.*)&.* $1 [L]

Upvotes: 1

Related Questions