Forum Moderators: phranque
I have been getting some traffic through a link at a popular site, but the link was posted incorrectly and I can't get the person to change it. The link is to a script on my site, but the link contains some obfuscated code in one of the parameter names after the? in the URL... %3Cbr%20/%3E to be exact, which depending on the browser seems to also be sent as '<br />'
This causes an error on my site. How can I redirect the bad link to the good link? Maybe just a filter to remove the bad code, or a full redirect to the correct dynamic link. I'd settle to redirect to a static page as well.
I am already using mod_rewrite for some other stuff, so it is enabled.
Thanks,
Dave
The server should resolve the encoded characters before mod_rewrite sees the URL, so you should be able to redirect the URLs containing "<br />" to whatever URL you like.
RewriteRule ^([^<]*)<br\ />(.*)$ /$1$2 [R=301,L]
RewriteRule ^([^%]*)\%3Cbr\%20/\%3E(.*)$ /$1$2 [R=301,L]
If this doesn't work, it would be helpful if you could post some lines from your server access log showing a few of these requests so we can look at them.
Jim
www.mysite.com/shop/amazon.cgi?input_item=12345&in<br />put_search_type=AsinSearch&input_templates=2
www.mysite.com/shop/amazon.cgi?input_item=12345&in<br%20/>put_search_type=AsinSearch&input_templates=2
www.mysite.com/shop/amazon.cgi?input_item=12345&in%3Cbr%20/%3Eput_search_type=AsinSearch&input_templates=2
So I added this to the .htaccess file along with what you told me:
RewriteRule ^([^<]*)<br\%20/>(.*)$ /$1$2 [R=301,L]
I also swapped out /$1$2 for another URL, but nothing seems to grab that url.
the .htaccess file was in the public_html/ directory, but I also tried it in the /shop/ directory. The first line of the file is RewriteEngine on
Dave
RewriteCond %{QUERY_STRING} ^in<br\ />(.*)$ [OR]
RewriteCond %{QUERY_STRING} ^in<br\%20/>(.*)$ [OR]
RewriteCond %{QUERY_STRING} ^in\%3Cbr\%20/\%3E(.*)$
RewriteRule ^shop\.amazon\.cgi$ /shop.amazon.cgi?in%1 [R=301,L]
RewriteCond %{QUERY_STRING} ^([^&]+)&in<br\ />(.*)$ [OR]
RewriteCond %{QUERY_STRING} ^([^&]+)&in<br\%20/>(.*)$ [OR]
RewriteCond %{QUERY_STRING} ^([^&]+)&in\%3Cbr\%20/\%3E(.*)$
RewriteRule ^shop\.amazon\.cgi$ /shop.amazon.cgi?$1&in%2 [R=301,L]
^ $ %? + * . ( ) { } [ ] ? ¦ \
Jim
RewriteRule ^shop/amazon\.cgi$ /shop/amazon.cgi?input_item=12345$1&in%2 [R=301,L]
Thanks again,
Dave