0

I am struggling with the last part, writing proper RewriteRule (maybe I also need RewriteCond?).

I have this mapping.txt:

apple 30/products/apple.png
xerox 38/products/xerox-300.png
dell 3021/products/dell_img.png
...

with it I want to do URL redirects as following:

https://www.domain-a.com/product_img/apple -> https://www.domain-b.com/img/30/products/apple.png
https://www.domain-a.com/product_img/xerox -> https://www.domain-b.com/img/38/products/xerox-300.png
...

in my .htaccess I have:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteMap redirect_map txt:/home/username/domains/domain-a/public_html/product_img/mapping.txt
RewriteRule * ${redirect_map:$1} // <--- struggling with this line
</IfModule>

How do I write proper RewriteRule for my case? I've tried many options without any luck yet. Secondly, should I have these rules in /public_html/.htaccess or create a new one in /public_html/product_img/.htaccess?

c0dehunter
  • 271
  • 4
  • 11
  • 2
    Presumably you are getting a 500 Internal Server Error? (In which case check your error log.) You can't _create_ a `RewriteMap` in `.htaccess` - you need access to the server config. Do you have access to the server config? – MrWhite Dec 19 '18 at 10:50
  • 1
    @MrWhite, exactly that was my problem. Due to being a shared hosting, I am not able to use RewriteMap at all. – c0dehunter Dec 19 '18 at 12:44
  • 1
    I've just noticed you have two different domains as well. You can't "rewrite" from one host to another - this will implicitly trigger an external redirect, which is not good for your server or users. You would need to implement a reverse proxy - but again, this is probably not possible on shared hosting. – MrWhite Dec 19 '18 at 12:59
  • Exactly, the redirects would be from my domain to some other 3rd party domain. Good to know. Best to solve in some other way without redirects. – c0dehunter Dec 19 '18 at 13:38

0 Answers0