Search code examples
mod-rewriteoracle-http-server

Having difficulty OHS rewrite rule for multiple domains


I'm having a bit of difficulty with rewriting on Oracle HTTP Server for multiple domains that point to same IP address and port

Following is working

  RewriteEngine On
  RewriteCond %{REQUEST_URI} ^/$
  RewriteRule ^(.*)$ https://sub-doamin-1/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL [R,L]

However when I try https://sub-doamin-2/analytic it redirects to the https://sub-doamin-1/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL

Tried RewriteCond ${HTTP_HOST} method with no luck. It just redirect to / (root)

RewriteEngine On
RewriteCond ${HTTP_HOST} sub-doamin-1$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub-doamin-1/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL [R,L]

RewriteCond ${HTTP_HOST} sub-doamin-2$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub-doamin-2/analytics

Can you please assists resolving this issue?


Solution

  • It should be %{HTTP_HOST} instead of ${HTTP_HOST}

    So the rules should be:

    RewriteCond %{HTTP_HOST} sub1.test.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^(.*)$ https://sub1.test.com/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL [R,L]
    
    RewriteCond %{HTTP_HOST} sub2.test.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^(.*)$ https://sub2.test.com/analytics [L]
    

    You can check the rules here: https://htaccess.madewithlove.be?share=6632e45c-a7bb-5099-ab0b-468ba1066277

    for the urls https://sub1.test.com and https://sub2.test.com

    If you write your original rules in that website you will get This test string is not supported: ${HTTP_HOST} so this can also help you next time.