Arabic characters in URL while sharing on Twitter

荒凉一梦 提交于 2020-12-08 05:34:12

问题


I'm facing an issue trying to sharing an URL which includes arabic characters on Twitter:

http://example.com/قرعة-تصفيات-أفريقيا-مصر-تواجه-نيجيريا/

When i click on "share" the same URL is showed in the tweet box, but when I actually tweet, it just links to http://example.com, and the rest of the URL is lost.

I tried using urlencode(), but the generated URL is too long and impossible tweet. How could I solve this?


回答1:


If you are owner of website, you can write htaccess RewriteRule for generate shorter or English url or use Redirection file.

RewriteEngine on 
RewriteRule ^redirect/(.*)/?$ ./redirector.php?key=$1 [QSA,L,NC]

And if you are user of website just you can use URL shorter websites like bit.ly or goo.gl




回答2:


You can use RewriteRule on .htaccess file or use URL shorter service instead




回答3:


This is an issue with two sides: Network and Presentation.

Network

URLs are never passed with other than ASCII characters. For example when you place a request for

http://example.com/عربي

It will generate an error or, depending on your client e.g. Chrome, will be converted to:

http://example.com/%D8%B9%D8%B1%D8%A8%D9%8A

Presentation

Internet browsers do their best to present this on the most readable way. For example when you request the following URL:

http://example.com/%D8%B9%D8%B1%D8%A8%D9%8A

Chrome will present it to the user as:

http://example.com/عربي

What Chrome also does is take care of copy and paste. So when you copy an URL in the top bar and it has Unicode characters, it will copy http://example.com/%D8%B9%D8%B1%D8%A8%D9%8A not http://example.com/عربي. Now what you need to do is check how twitter deals with this. It might already do some presentation to ease user experience. However, on the network side, you cant do much really.




回答4:


I use URL-shortening websites e.g. goo.gl; however it is more time consuming then posting a plain URL.



来源:https://stackoverflow.com/questions/29650315/arabic-characters-in-url-while-sharing-on-twitter

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