1

I'm trying to make the user type an easier URL.

So users query for: https://example.com/invoices/X123

And the .htaccess would rewrite (mask) to

https://api.example.com/invoices/1/getInvoicefromHash.html?hash=X123

But somehow it does not work. It just redirects...

This is my .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^invoices/(.*)$ http://api.domain.com/1/getInvoicefromHash.html?hash=$1 [QSA,L]   
MrWhite
  • 11,643
  • 4
  • 25
  • 40
Miguel
  • 121
  • 4
  • 1
    You can't internally rewrite to a different host, attempting to do so will implicitly trigger an external redirect (like you are seeing). Infact, simply specifying an absolute URL (including scheme) will trigger an external redirect (despite what the docs appear to say). You would need to use mod_proxy instead. Alternatively, if the subdomain just points to a location on the same filesystem (a subdirectory perhaps?) then you can avoid changing the hostname. (?) – MrWhite Nov 21 '16 at 13:49
  • Then again, if you just want "the user type an easier URL" - then isn't a redirect preferable? Or are you also linking to this "pretty" URL? – MrWhite Nov 21 '16 at 13:55
  • 1
    yes i don't want the user to know that API under-the-scene thing... its ugly and i dont want them to play with the endpoint, even if its secured... In this case the same filesystem is true. I just not sure if doing the same url rewrite that the api itself does for its "models" will work in the same way, have to test... Thanks by the way. – Miguel Nov 21 '16 at 13:59

0 Answers0