0

In my website has many JS files and I want if a particular JS is loaded in the browser then rewrite will call a servlet in another domain.

For this I have added following lines :

 <VirtualHost *:80>
 ServerName mydomain.com
 RewriteEngine On
 RewriteCond %{REQUEST_URI} ^/someresource.js
 RewriteRule ^/someresource.js http://anotherdomain.com/bin/test/custom [R=301,L]
 </VirtualHost>

When I see the output in the browser console, it says that Http Method OPTIONS was executed instead of GET call. As a result I am not getting the desired output which is supposed to execute in this call http://anotherdomain.com/bin/test/custom

The servlet(/bin/test/custom) has only doGet method.

If I hit this url directly in the browser mydomain.com/someresource.js then redirect works correctly. But it does not work when the browser loads someresource.js

What am I doing wrong?

Pakira
  • 1,951
  • 3
  • 25
  • 54
  • Probably an issue with CORS https://stackoverflow.com/questions/30254277/angular-http-is-sending-options-instead-of-put-post – wp78de May 18 '18 at 05:53

1 Answers1

0

I do not think a rewrite is what you need here. If you want to have a redirect, use

Redirect 301 /someresource.js http://anotherdomain.com/bin/test/custom

If you want to hide the redirect from the user, so you rather use your webserver as a proxy, use mod_proxy: https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html

hth

Oliver Gebert
  • 1,166
  • 1
  • 6
  • 20