2

I'm trying to make the following redirection (301) using .htaccess for mp3, jpg, jpeg, png & gif files only.

http://website.com/file.jpg?c=XXXX is replaced with http://website.com/file.jpg

Basically, I want to strip the query (ie. "?c=XXXX") from end of media url's. I want to prevent anyone accessing an image or mp3 with "?c=XXXX" at the end of the URL, and instead direct them to the same file url minus '?c=XXXX'.

Is there a quick way of doing this?

Many thanks!

1

1 Answer 1

1

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} !^$
RewriteRule \.(mp3|jpe?g|png|gif)$ %{REQUEST_URI}? [L,R]
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @anubhava This has been a great help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.