Remove string from URL using .htaccees [closed]

☆樱花仙子☆ 提交于 2019-12-12 06:49:54

问题


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!


回答1:


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/.



来源:https://stackoverflow.com/questions/16173653/remove-string-from-url-using-htaccees

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!