Search code examples
phpapache.htaccessmod-rewrite

.htaccess RewriteRule not working after switching providers


I want to have a short link for images hosted on my website. An example:

http://example.com/sharex/user/UUd.png

The short link:

i.example.com/nUUd

The subdomain "i" redirects to http://example.com/sharex, and the "n" character indicates the directory the file is stored in. The expected behaviour is to visit the short link, and view the image file hosted at the long link (without the URL changing in the browser).

Here's the .htaccess file I have in the /sharex/ directory:

RewriteEngine On
RewriteBase /
RewriteRule ^n(.*)$ /user/$1.png [P,L]

This issue presented itself after switching hosting providers, even though the exact same thing worked on my previous host.


Solution

  • This is assuming your have mod_proxy correctly setup on new host.

    Fix your RewriteBase and use a relative URI in target:

    RewriteEngine On
    RewriteBase /sharex/
    
    RewriteRule ^n(.*)$ quartzic/$1.png [P,NC,L]