Philo's Website
 

Fixing AliExpress Links Out Of Frustration

Some of my friends have been, for want of a better word, doomscrolling AliExpress, looking for parts they could use in projects. They send their most interesting finds in a Discord chat, of course, but Discord doesn’t show a preview for AliExpress links.

I got frustrated at having to click through every time and decided to write some PHP about it. Welcome to fxaliexpress.com.

To use it, simply change “aliexpress.com” or “aliexpress.us” to “fxaliexpress.com”, and you’ll get a preview in chat and a link that takes you to the item’s page.


Making it work ended up being easier than I’d hoped. AliExpress actually already includes the code Discord needs for a preview in their pages, but they accidentally block Discord as part of their anti-scraping defenses.
    <meta property="og:url" content="//www.aliexpress.com/item/3256809935273137.html?src=ibdm_d03p0558e02r02&sk=&aff_platform=&aff_trace_key=&af=&cv=&cn=&dp=&aff_short_key=" />
    <meta property="og:title" content="3Pcs Pneumatic stainless steel mini magnetic cylinder CDJ2B10 CDJ2B16 Series 5 10 15 20 25 50 75 100 150 200mm Stroke - AliExpress 13" />
    <meta property="og:type" content="product" />
    <meta property="og:image" content="https://ae01.alicdn.com/kf/S6dd36d1bb23c4cf5b4c04551efa316c9V.jpg"/>
    <meta property="og:description" content="Smarter Shopping, Better Living! Aliexpress.com" />
    <meta property="og:site_name" content="aliexpress." />
    
the preview tags from a random part on AliExpress; the indentation has been corrected from the original
A browser needs to accept cookies to visit an AliExpress page, or else it’ll be sent in an infinite redirect loop between the item page and the page that issues the cookie and (hopefully) eventually give up. My code accepts the cookies, hands them back when redirected, and gets through to the item page. From the item page, it extracts the tags and serves them up as a page of its own that Discord can actually access and display.

I wrote this in PHP because it’s what I’m comfiest with for dynamic webpages. I added some rules to my web server’s configuration to rewrite URLs shaped like AliExpress’ into parameters passed to my PHP script and it was ready to test.
        DocumentRoot /var/www/fx
        <Directory "/var/www/fx">
                RewriteEngine On
                RewriteRule ^item/(.*) /item.php?id=$1 [L]
        </Directory>
    
Once I was satisfied that it worked, I went out and spent $11 on the domain name, set up a TLS certificate, and everything was ready. (I was tempted to get fxaliexpress.us as well, but the lack of domain privacy on that leaves me open to more spam than I’d like.)

If you'd like to take a look at the code, you can download it here .

Thanks for reading this shorter post than usual!