Question

I've set up a bit.ly link and printed it on 1000 flyers. Somehow the bit.ly target link contains some strings which shouldn't be there (https://example.com/page/%E2%80%8E instead of https://example.com/page/)

Can I get rid of this string using rewrite rules in .htaccess?

Any help is appreciated!

Was it helpful?

Solution

When you just accidentally added the string %20%E2%80%8E in the creation of the short link, then you can just get another short link without accidentally added the string again.

Anyway, I think these .htaccess directives are what you want:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9_-]+)\%20\%E2\%80\%8E$
RewriteRule ^(.*) https://example.com/%1 [R,L]

It will redirect example.com/$anything%20%E2%80%8E into example.com/$anything

Just make sure that there's Apache HTTP Server with mod_rewrite on your web hosting account. And considered this link about the [R=301] flag: https://stackoverflow.com/a/15999177/2007055.


This code:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9_-]+)/\%20\%E2\%80\%8E$
RewriteRule ^(.*) https://example.com/%1/ [R,L]

Is to redirect example.com/$anything/%20%E2%80%8E into example.com/$anything/.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top