1

I need some help with .htaccess redirect.

http://www.example.de/test-music.html?p1=1&p2[test]=23
http://www.example.de/test-music.html?p1=6&p2[test3]=5

ALL of them need to be redirected to ...

http://www.example.de/music/

... without taking care of any parameters - can you help me?

| improve this question | | | | |
1

Very easy, this is something you can easily find and figure out yourself.

# Check if the url STARTS WITH (is what the ^ does) '/test-music'
RewriteCond %{REQUEST_URI} ^/test-music
# redirect it, 301 style, Last line (we go away, no need to do the rest of the htaccess)
RewriteRule ^(.*) /music/ [L,R=301]
| improve this answer | | | | |
  • Very nice - Thanks! :-) But for me, I had to add a '?' after the last '/' - then all parameters will be deleted ... RewriteRule ^(.*) /music/? [L,R=301] – Nico Jul 8 '15 at 23:54
  • Thats weird, because that isnt the regex part. I don't put the varaibles back in the url (that would mean $1 would be put there). But hey, if it works! – Martijn Jul 9 '15 at 7:09
  • Seem that adding a ? after the new URL in the RewriteRule line is what makes the parameters not append to the URL. I think there may be a flag included with apache 2.4 that can be used to also force the removal of parameters as well but I'm not sure of the name of it. – Mike Jul 9 '15 at 17:57
1
RewriteRule ^test-music\.html$ /music/ [L,R=301]
| improve this answer | | | | |
  • +1, this might be easier. But is a bit more limited, you can't do a if file doesnt exist check if someone wants that. Pick whichever suits you better :) – Martijn Jul 9 '15 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.